六 CF2184B 3313 DFS 求被210整除的n位数

来源:互联网 发布:家里wifi有信号没网络 编辑:程序博客网 时间:2024/05/16 10:17

e

Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

Dreamtale loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7, he came up a game that were connected with them.
 
Deamtale wants to find the minimum number of length n, such that it is simultaneously divisible by all numbers Dreamtale 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.

输入

A single input line contains a single integer n (1≤n≤10^5).

输出

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.

示例输入

15

示例输出

-110080

提示

 

来源

#include<iostream>#include<cstring>#include<cstdlib>#include<cmath>#include<cstdio>using namespace std;int n,flag=0;int output[1000010];int DFS(int num,int ans){    if(flag||num>n)        return 0;    if(num==n)    {        if(ans==0)        {            flag=1;           return 1;        }    }    for(int i=0;i<=9;i++){if(flag==1)//必须找到后就跳出,防止篡改后面的output[];<span id="transmark"></span> return 1;int k=(ans*10+i)%210;         output[num]=i;DFS(num+1,k);}}int main(){    while(~scanf("%d",&n))    {    flag=0;    for(int i=1;i<=9;i++){ output[0]=i;         DFS(1,i);         if(flag)break;}        if(flag)        for(int i=0;i<n;i++){printf("%d",output[i]);}elseprintf("-1");printf("\n");    }}


0 0
原创粉丝点击