Number
时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
总提交:23 测试通过:20
总提交:23 测试通过:20
描述
Given an equation (a*x+b)%n=0,where a,b,n are positive integer ,please find out the least positive integer x make that equation holds.
输入
There are several test cases .one line for each case ,For each line ,three positive integers,all of which are no than 2000000000.Input number have no leading zeros .There will be no more than 1000 teat cases.
Input is ended with three 0.
输出
Output each result in a single line .Output number must not have any leading zeros.If there is no positive integer makes the equation holds ,then output -1.
样例输入
1 1 1
1 1 2
1 1 3
3 4 5
5 1 5
0 0 0
1 1 2
1 1 3
3 4 5
5 1 5
0 0 0
样例输出
1
1
2
2
-1
1
2
2
-1
#include<iostream>
int main(void){
unsigned int a, b, n;
unsigned int x;
while (scanf("%u%u%u", &a, &b, &n), a && b && n){
if (a % n == 0 && b % n != 0){
printf("-1\n");
}
else{
for (x = 1; (a * x + b) % n != 0; ++x){
continue;
}
printf("%u\n", x);
}
}
return 0;
}