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

来源:互联网 发布:外交部霸气发言知乎 编辑:程序博客网 时间:2024/06/05 02:32

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

3612

#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;
}

0 0
原创粉丝点击