链接
题目
对于一个五位数12345
定义a = 123, b = 234, c = 345
现在要求10000~30000中a,b,c均可被k整除
样例输入
15
样例输出
22555
25555
28555
30000
思路
直接暴力枚举10000~30000然后再求出a,b,c,判断即可
a
=
s
/
100
a = s\ /\ 100
a=s / 100
b
=
(
s
/
10
)
m
o
d
1000
b = (s\ /\ 10)\ mod\ 1000
b=(s / 10) mod 1000
c
=
s
m
o
d
1000
c = s\ mod\ 1000
c=s mod 1000
代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int k, s1, s2, s3;
bool b;
int main()
{
// freopen("num.in", "r", stdin);
// freopen("num.out", "w", stdout);
scanf("%d", &k);
for(int i = 10000; i <= 30000; ++i)
{
s1 = i / 100;
s2 = (i / 10) % 1000;
s3 = i % 1000;
if(s1 % k == 0 && s2 % k == 0 && s3 % k == 0)
printf("%d\n", i), b = 1;
}
if(!b) printf("No");
return 0;
fclose(stdin);
fclose(stdout);
}