转化为e_gcd(1576)
来源:互联网 发布:怎么申请淘宝网店 编辑:程序博客网 时间:2024/05/14 23:35
A/B
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3707 Accepted Submission(s): 2835
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)。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
Output
对应每组数据输出(A/B)%9973。
Sample Input
21000 5387 123456789
Sample Output
79226060
原题要求(A/B)%9973且n=A%9973 -->Bx=A --> Bx=n (mod 9973) --> Bx+9973y=n 求解x在(0,9973)的最小整数解,所以这就化成了一个标准的扩展欧几里德算法的乘法逆元。原题还有条件:gcd(B,9973)=1。所以此不定方程必有解。
/*------------------Header Files------------------*/#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <algorithm>#include <cstdlib>#include <ctype.h>#include <cmath>#include <stack>#include <queue>#include <deque>#include <map>#include <vector>#include <set>#include <limits.h>using namespace std;/*------------------Definitions-------------------*/#define LL long long#define uLL unsigned long long#define PI acos(-1.0)#define INF 0x3F3F3F3F#define MOD 9973#define MAX 100050#define lson rt<<1,l,m#define rson rt<<1|1,m+1,r/*---------------------Work-----------------------*/LL e_gcd(LL a,LL b,LL &x,LL &y){if(b==0){x=1,y=0;return a;}LL ans=e_gcd(b,a%b,x,y);LL temp=x;x=y;y=temp-a/b*y;return ans;}LL cal(LL a,LL b,LL c){LL x,y;LL gcd=e_gcd(a,b,x,y);if(c%gcd!=0) return -1;x*=c/gcd;b/=gcd;if(b<0) b=-b;LL ans=x%b;if(ans<=0) ans+=b;return ans;}void work(){int T; cin>>T;while(T--){int n;LL b;scanf("%d%I64d",&n,&b);printf("%I64d\n",cal(b,9973,n));}}/*------------------Main Function------------------*/int main(){//freopen("test.txt","r",stdin);work();return 0;}
0 0
- 转化为e_gcd(1576)
- 汉字转化为拼音
- 汉字转化为拼音
- 汉字转化为拼音
- dataReader转化为dataTable
- ServerStyle转化为图片
- char* 转化为int
- word转化为PDF
- word转化为html
- word转化为图片
- DataReader转化为DataSet
- 字符串转化为日期
- 字符串转化为int
- 整数转化为字符串
- 数字转化为英文
- GridView转化为DataTable
- 十六进制转化为二进制
- list转化为xml
- 收藏图标--属性动画
- CentOS不常用命令记录
- 关于IME禁用
- 正则表达式的使用
- 超赞干货!一个完整的UI设计流程是怎样的?
- 转化为e_gcd(1576)
- java帮助文档的的制作
- VTK Error setting 'tcoordMC' in shader VAO.
- mysqli连接提示 Warning: mysqli::mysqli(): (HY000/2002): No such file or directory
- 5.2趣味素数之哥德巴赫猜想
- LeetCode 213. House Robber II
- 数组排序问题(指针)
- IOS AES 128 ECB PKCS7Padding 16进制加密解密
- 项目管理的十大原则