欧几里得要复仇!那么我们闲话少说,看看这个小兔崽子要干嘛吧~~
看题!
英文的哦~
Description
In 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.
Input
The 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
Output
For each test case, output the number of valid pairs.
Sample Input
2
1 2 3
1 1 4
Sample Output
1
3
好吧,看不懂,我们看中文的
描述
在算术和计算机编程中,扩展欧几里德算法是欧几里德算法的扩展,除了整数a和b的最大公约数之外,它还计算Bézout同一性的系数,即整数x和y,使得ax + by = gcd(a,b)。
---维基百科
今天,前欧几里德报复你。对于给定的a,b和c,您需要计算(x,y)有多少个不同的正对(例如ax + by = c)。
输入
第一行包含单个整数T,表示测试用例的数量。
每个测试用例仅包含三个整数a,b和c。
[技术规范]
1. 1 <= T <= 100
2. 1 <= a,b,c <= 1 000 000
产量
对于每个测试用例,输出有效对的数量。
样本输入
2
1 2 3
1 1 4
样本输出
1
3
然后我们来看一下代码:
if((c-a*j)%b==0)如果求余等于零,说明要求的数是整数,计数器加一。
if((c-a*j)<=0) 如果结果小于零,根本不符合,直接跳出。
#include<stdio.h>
#include<string.h>
int main()
{
long long int a,b,c,t,i,j,k,s=0;
scanf("%lld",&t);
for(i=1;i<=t;i++)
{
s=0;
scanf("%lld %lld %lld",&a,&b,&c);
for(j=1;;j++)
{
if((c-a*j)<=0)
break;
if((c-a*j)%b==0)
s++;
}
printf("%lld\n",s);
}
return 0;
}