HDU 4993 revenge of ex-Euclid)

Source: Internet
Author: User
Tags greatest common divisor

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.