Chilly Willy(CF-248B)
Problem Description
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 and 7). Help him with that.
A number's length is the number of digits in its decimal representation without leading zeros.
Input
A single input line contains a single integer n (1 ≤ n ≤ 105).
Output
Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist.
Examples
Input
1
Output
-1
Input
5
Output
10080
题意:给出一个 n,要找一个数字位数为 n,且能被 2、3、5、7 整除的最小数字
思路:
2、3、5、7 最小公倍数为 210,因此当 n<3 时,找不到,输出 -1
当 n>=3 时,最小的数字最多从 1E(n-1) 枚举 210 个,因此直接暴力即可
由于 n 最大到 1E6,需要使用大数
Source Program
def quickPow(a,b):
res=1
while b:
if b&1:
res=res*a
a=a*a
b>>=1
return res
n=int(input())
if n==1 or n==2:
print(-1)
else:
n=quickPow(10,n-1)
while 1:
if(n%210==0):
print(n)
break
n+=1

浙公网安备 33010602011771号