您的位置:首页 > 其它

CodeForces 248B Chilly Willy

2014-04-22 17:48 302 查看
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7.But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.Chilly Willy wants to find the minimum number of length n, such that it is simultaneously divisible by all numbers Willy already knows (2, 3, 5 and7).Help him with that.A number's length is the number of digits in its decimal representation without leading zeros.InputA single input line contains a single integer n (1 ≤ n ≤ 105).OutputPrint a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem conditiondoes not exist.Sample test(s)input
1
output
-1
input
5
output
10080
题意很简单就不提了 要找到210的倍数 很明显只用考虑后三位  最后一位一定为0,因此找规律可以得到6个数一个循环
"05", "08", "17", "02", "20", "11"
代码如下:
#include <stdio.h>

void solve(int n){
char a[7][3]={"05", "08", "17", "02", "20", "11"};
if (n <= 3) {
printf("%d\n", n == 3 ? 210 : -1);
return ;
}
int tmp = (n - 4) % 6;
printf("1");
for (int i = 0; i < n - 4; ++ i)
printf("0");
printf("%s0\n", a[tmp]);
}

int main(){
int n;
while (~scanf("%d", &n)){
solve(n);
}
return 0;
}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: