您的位置:首页 > 其它

Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in d

2016-10-13 00:43 1386 查看
Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many digits are in the smallest such a multiple
of n?

Sample Input
3
7
9901

Sample Output
3
6
12


#include<iostream>

using namespace std;

int main()

{

int n;

while (cin >>n &&n!=EOF)
{
int ans = 1;
int m = 1;
while (m %= n)           (注意while括号中的表达式已经能表示一个值是否存在,是否有意义,不需要再写出while(m%n==0)这样写当值大到一定程度时会输不出结果 ,运行时间需要的太长了)
{

m =m * 10 + 1;
ans++;
;
}
cout <<ans<<endl;

}

return  0;

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