UVa 550 - Multiplying by Rotation

来源:互联网 发布:防网络上瘾安全教育 编辑:程序博客网 时间:2024/04/28 05:47
/*数学,模拟n进制乘法*/#include <cstdio>#include <cmath>#include <cstring>using namespace std;int s, a, b;int main() {    #ifndef ONLINE_JUDGE    freopen("in.txt", "r", stdin);    #endif    while(scanf("%d%d%d", &s, &a, &b) == 3) {        int c = 0, k = a, sum = 0;        int cnt = 0;        while(c!=0 || k!=a || cnt==0) {            sum = k*b + c;            c = sum / s;            k = sum % s;            cnt++;        }        printf("%d\n", cnt);    }    return 0;}