数字47一向被数学界的人认为是很魔幻的一个数字,和47有关的任务被认为是魔幻任务。某天,doubleegg正在做着这类魔幻任务,路过的奇牛看到了,他说,你研究了老半天,研究出了什么?我来问你个简单的问题,我想知道长度为n位能够被47整除最小的数,你会吗?会吗?吗??由于doubleegg已经被奇牛的气场震晕过去,所以这个魔幻任务只能交给你了,聪明的你,一定想得到的。
数字47一向被数学界的人认为是很魔幻的一个数字,和47有关的任务被认为是魔幻任务。某天,doubleegg正在做着这类魔幻任务,路过的奇牛看到了,他说,你研究了老半天,研究出了什么?我来问你个简单的问题,我想知道长度为n位能够被47整除最小的数,你会吗?会吗?吗??由于doubleegg已经被奇牛的气场震晕过去,所以这个魔幻任务只能交给你了,聪明的你,一定想得到的。
第一行输入一个样例数T(T<=1000)
下面每一行输入一个n(n<=10000)
每一行输出一个答案,假设不存在,输出-1
re = 10^n + 47 - 10^n % 47;
当n == 0,1,2时候加上特判就好
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #include <cmath> 7 #include <time.h> 8 #include <string> 9 #include <map> 10 #include <stack> 11 #include <vector> 12 #include <set> 13 #include <queue> 14 #define M 10000 15 #define maxn (6 + 2) 16 #define pi acos(-1.0) 17 using namespace std; 18 int main() 19 { 20 // freopen("in.txt","r",stdin); 21 // freopen("out.txt","w",stdout); 22 int t; 23 scanf("%d",&t); 24 while(t --) 25 { 26 int n,re = 1,temp; 27 scanf("%d",&n); 28 if(n == 0) printf("-1\n"); 29 else if(n == 1) printf("0\n"); 30 else if(n == 2) printf("47\n"); 31 else 32 { 33 for(int i = 0; i < n - 1; i ++) re = re * 10 % 47; 34 re = 47 - re; 35 temp = int(log(re * 1.0) / log(10.0) + 1); 36 for(int i = 0; i < n - temp; i ++) 37 printf("%d",i == 0 ? 1 : 0); 38 printf("%d\n",re); 39 } 40 } 41 42 return 0; 43 } 44 45 /************************************************************** 46 Problem: 1140 47 User: Assassin_upc 48 Language: C++ 49 Result: Accepted 50 Time:420 ms 51 Memory:1876 kb 52 ****************************************************************/
原文:http://www.cnblogs.com/zouqihan/p/5027430.html