uva10127oenes模算术

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85482#problem/L

题意:输入n,n*b得到一个每一位上都是1的数,输出这个数的位数(有多少个1)。

思路:数论。找到能整除n的由1组成的数,其中判断能否整除时用模算术。

#include<iostream>
using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        int cnt=1;
        long long a=1;
        while(a%n)
        {
            a=a%n*10+1;
            cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

 

posted @ 2016-04-29 11:53  哲贤  阅读(111)  评论(0编辑  收藏  举报