六 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
- 六 CF2184B 3313 DFS 求被210整除的n位数
- 求N!的位数
- 求N!的位数
- 求N!的位数
- 输出一个N位数,使它的前n位能被n整除【回溯】
- 1~9的9个数组成9位数并前n为能被n整除
- 1-9组成9位数,各位不同,前n位能被n整除的算法
- 求大数n!的位数
- PKU1423:求n!的位数。
- 求所有位数之和能被另一个数整除的序列
- 内部赛题目 求一个数能否被3整除 求每一位数的和时 要减去字符0
- 求N的阶乘的位数
- 求n的阶乘的位数
- LightOJ 1045 求N!的位数
- 湖北工业大学 1783 求n!的位数
- 【HDU1018】Big Number - 求n!的位数
- 求N!的位数(斯特林公式)
- hdu1018(求n!的位数)
- 标准库vector类型
- 各大Oj平台介绍
- 1050. String Subtraction (20)
- 软件收费不收费有几种?
- DAY 2
- 六 CF2184B 3313 DFS 求被210整除的n位数
- js或jquery实现页面打印可局部打印
- JavaScript二维数组的使用及删除指定元素
- CCF-数字排序-201503-2
- 【linux主机管理面板AMH4.2】安装使用教程,集成PHP建站环境
- java基础加强
- HTTP 请求方式: GET和POST
- motor知识备忘
- 在myeclipse10.7中安装SVN插件