您的位置:首页 > 其它

【数论,水题】UVa 10127 - Ones

2015-03-21 11:11 253 查看

题目链接

题意:给你一个数n,问最少有多少个1构成的“1”串(1,11,...)能整除n;

比如:111能被3整除; 111111能被7整除;...

作为水货觉得只要自己能1A的都是水题=。 =

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
const int maxn = 10010;
int main()
{
int n, p[maxn];
while(~scanf("%d", &n))
{
if(!n) {printf("0\n"); continue;}
int len = log10(n)+1;
int val = 0, x;
for(x = 0; x < len; x++)
{
val = val*10 + 1;
}
int res = 0;
if(val/n == 0)
{
val = val*10+1;
x++;
}
res = val%n;
while(res)
{
res = res*10+1;
res = res%n;
x++;
}
printf("%d\n", x);
}
return 0;
}
View Code

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: