题意:给你一个数n,问最少有多少个1构成的“1”串(1,11,...)能整除n;
比如:111能被3整除; 111111能被7整除;...
作为水货觉得只要自己能1A的都是水题=。 =
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cmath> 5 using namespace std; 6 const int maxn = 10010; 7 int main() 8 { 9 int n, p[maxn]; 10 while(~scanf("%d", &n)) 11 { 12 if(!n) {printf("0\n"); continue;} 13 int len = log10(n)+1; 14 int val = 0, x; 15 for(x = 0; x < len; x++) 16 { 17 val = val*10 + 1; 18 } 19 int res = 0; 20 if(val/n == 0) 21 { 22 val = val*10+1; 23 x++; 24 } 25 res = val%n; 26 while(res) 27 { 28 res = res*10+1; 29 res = res%n; 30 x++; 31 } 32 printf("%d\n", x); 33 } 34 return 0; 35 }
时间: 2024-10-21 10:04:40