您的位置:首页 > 编程语言 > C语言/C++

UVA 550-Multiplying by Rotation

2016-07-19 19:46 183 查看

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 uva