Hdu1576 a/B, analog Element

Source: Internet
Author: User

Time limit: 1000 ms Memory limit: 32768kb 64bit Io format: % I64d & % i64

Description

(A/B) % 9973, but because a is very large, we only give n (n = A % 9973) (the given a must be divisible by B, and gcd (B, 9973) = 1 ).

Input

The first row of data is a T, indicating that there is a T group of data.
Each data set has two data sets: n (0 <= n <9973) and B (1 <= B <= 10 ^ 9 ).

Output

Corresponding to each group of data output (a/B) % 9973.

Sample Input

21000 5387 123456789

Sample output

79226060 is nothing to say .. Bx-9973y = N;
 1 #include<cstdio> 2  3 int T,n,B,x,y; 4  5 int extend_eculid(int a,int b,int &x,int &y){ 6     if(!b){ 7         x=1;y=0; 8         return a; 9     }10     int d=extend_eculid(b,a%b,x,y);11     int t=x;x=y;y=t-a/b*x;12     return d;13 }14 15 int main(){16     scanf("%d",&T);17     while(T--){18         scanf("%d%d",&n,&B);19         int d=extend_eculid(B,9973,x,y);20         printf("%d\n",((x*n/d%9973)+9973)%9973);21     }22 }

 

Hdu1576 a/B, analog Element

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.