poj 1576 A/B
来源:互联网 发布:轩辕传奇辅助软件 编辑:程序博客网 时间:2024/06/09 16:48
A=B*x1;
n=A%9973=A-9973*y1,则n=B*x1-9973*y1;
因为 gcd(B,9973)= 1 = B*X+9973Y; 两边*n ,得 n=B*X*n+9973*Y*n;所以x1=X*n
欧几里德原理好奇妙,可以解决好多问题,数学真神奇
#include<stdio.h>#include<math.h>const int k=9973;/*根据朴素的欧几里德原理有 gcd(a,b) = gcd(b,a mod b);则:ax1+ by1= bx2+ (a mod b)y2;即:ax1+ by1= bx2+ (a - [a / b] * b)y2=ay2+ bx2- [a / b] * by2;也就是ax1+ by1 == ay2+ b(x2- [a / b] *y2);根据恒等定理得:x1=y2; y1=x2- [a / b] *y2;*/void exgcd(int a,int b,int &x,int &y){ if(b==0) { x=1,y=0; return ; } exgcd(b,a%b,x,y); int t=x; x=y; y=t-(a/b)*y;}int main(){ int t,n,b,x,y,ans; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&b); exgcd(b,k,x,y); x*=n; ans=(x%k+k)%k; printf("%d\n",ans); } return 0;}
0 0
- poj 1576 A/B
- poj 1000 a+b
- poj 1001 a+b
- poj 1000 A+B Problem
- POJ 1000 A+B Problem
- [POJ][1000]A+B Problem
- POJ 1000 A+B Problem
- 【POJ】1000 A+B Problem
- POJ 1000:A+B Problem
- POJ 1000: A+B Problem
- poj 1000 A+B Problem
- POJ 1000 A+B Problem
- POJ 1000 A+B Problem
- POJ 1000 A+B Problem
- POJ 1000 A+B Problem
- POJ 1000 A+B Problem
- POJ 1000 A+B Problem
- POJ 1000 A+B Problem
- Android应用进程防杀指南3-JobService
- c 语言 递归法倒叙打印链表的节点
- H.264流媒体协议格式中的Annex B格式和AVCC格式深度解析
- POJ1273&&HDU1532-Drainage Ditches
- Caffe 实践DeepID(人脸识别)
- poj 1576 A/B
- 关于error LNK2019: 无法解析的外部符号 __imp__WSAStartup@8 __imp__gethostbyname@4 __imp__gethostbyname@4 __imp__
- struts2 s:select 标签
- poj 3272
- c++第三周
- 76. Minimum Window Substring
- JS和Android交互调用
- 10.1
- Java Servlet完全教程