virtual hust 2013.6.20 数论基础题目 C - Multiplying by Rotation

题目:Multiplying by Rotation

思路:求base进制下,长度最短的数字满足乘以factor,使得原来的最低位等于最高位。

 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
    int base,first,factor;
    while(cin>>base>>first>>factor)
    {
        int now=first*factor;
        int ans=1;
        while(first!=now)
        {
            now=(now%base)*factor+now/base;
            ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}
View Code

 

posted @ 2013-06-21 00:28  over_flow  阅读(124)  评论(0编辑  收藏  举报