Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4993
Problem descriptionin arithmetic and computer programming, the Extended Euclidean algorithm is an extension to the Euclidean algorithm, which computes, besides the greatest common divisor of integers A and B, the coefficients of bé Zout's identity, that is integers x and y such that ax + by = gcd (A, B ).
--- Wikipedia
Today, ex-Euclid takes revenge on you. You need to calculate how many distinct positive pairs of (x, y) such as AX + by = C for given A, B and C.
Inputthe first line contains a single integer T, indicating the number of test cases.
Each test case only contains three integers A, B and C.
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= A, B, C <= 1 000 000
Outputfor each test case, output the number of valid pairs.
Sample Input
21 2 31 1 4
Sample output
13
Sourcebestcoder round #9
Question:
How many group solutions does AX + by = C have!
The Code is as follows:
#include <cstdio>#include <cmath>int main(){ int t; int a,b,c; scanf("%d",&t); while(t--) { scanf("%d%d%d",&a,&b,&c); int k=0; for(int x = 1; x*a < c; x++) { if((c-a*x)%b == 0) k++; } printf("%d\n",k); } return 0;}
HDU 4993 revenge of ex-Euclid)