A/B

来源:互联网 发布:为什么凌晨五点醒 知乎 编辑:程序博客网 时间:2024/06/07 08:41
A/B
Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 22   Accepted Submission(s) : 17

Font: Times New Roman | Verdana |Georgia

Font Size:

Problem Description

要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。

Input

数据的第一行是一个T,表示有T组数据。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。

Output

对应每组数据输出(A/B)%9973。

Sample Input

21000 5387 123456789

Sample Output

79226060

Author

xhd

Source

HDU 2007-1 Programming Contest
#include<stdio.h>void gcd(int a, int b,int &x,int &y)    //  a*x+b*y==1  如果要求  a*x1+b*y1==n 中的 x1 只需要 x1=x*n{if (b == 0){x = 1;y = 0;return;               //    return a;   求最大公约数     }elsegcd(b, a%b,x,y);int sum=x;x = y;y = sum - a / b*y;}int main(){int  a,b=9973, x, y,n,t;scanf("%d", &t);while(t--){scanf("%d%d", &n, &a);gcd(a ,b,x,y);x *= n; //  x   a*x+b*y==1  中的 xx = (x %b + b) % b;   //  防止 x 为负数printf("%d\n",x);}return 0;}

0 0
原创粉丝点击