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
1output
-1input
5output
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; }
相关文章推荐
- Codeforces 460C —— Present(二分答案)
- Codeforces 484C Strange Sorting
- [Codeforces 697D] Puzzles (期望)
- codeforces 743D Chloe and pleasant prizes (DFS/树形DP)
- Codeforces 827C/828E DNA Evolution[树状数组]
- 【提醒自己】CodeForces - 847H Load Testing
- CodeForces 355E Vasya and Beautiful Arrays
- codeforces 601C(概率dp)
- CODEFORCES 445B DZY Loves Chemistry
- codeforces 746 A.Compote【水题】
- CodeForces 828C【构造】
- Codeforces 839C Journey (树形dp + 概率期望)
- Codeforces 459C Pashmak and Buses 机智数学题
- CodeForces 600C Make Palindrome 贪心
- Codeforces 696A. Lorenzo Von Matterhorn(map离散化)
- codeforces 388 div2 749B - Parallelogram is Back
- Codeforces 828C String Reconstruction【思维+并查集】
- CodeForces 142B(Help General)
- Codeforces 223A Bracket Sequence [栈]
- CodeForces 498A-Crazy Town-简单计算几何