UVA 550-Multiplying by Rotation
题目大意:给出m的尾数a,进制b,乘数c,使m*n=m的尾数a移到首位。
解题思路:模拟即可,使某位相乘等于a时跳出循环
#include <stdio.h>
#include <iostream>
using namespace std;
int main() {
long long int a, b, c;
while(scanf("%lld%lld%lld", &a, &b ,&c) != EOF) {
long long int x = b;
long long int z = 0;
long long int m = 1;
while(1) {
if(x * c + z == b)
break;
long long int k = x;
x = (x * c + z) % a;
z = (k * c + z) / a;
m++;
}
printf("%lld\n", m);
}
return 0;
}