Uva--550 (数学)

2014-06-10 23:50:45

题意&思路:直接模拟,处理进制时注意取模

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int main(){
    int Base,d,f,t,c,cnt;
    while(scanf("%d %d %d",&Base,&d,&f) == 3){
        for(cnt = 1,c = 0,t = d;;){
            t = (t * f) + c;
            c = t / Base;
            t = t % Base;
            if(c || t != d)
                ++cnt;
            else
                break;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

 

posted @ 2014-06-10 23:51  Naturain  阅读(103)  评论(0编辑  收藏  举报