#include<iostream> using namespace std; int gcd(int a,int b,int &x,int &y){ if (b==0){ x=1,y=0; return a; } int q=gcd(b,a%b,y,x); y-=a/b*x; return q; } int main() { int n, m, x, y; cin>>m>>n; gcd(m, n, x, y); cout<<(x+n)%n&…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4020 Accepted Submission(s): 3091 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%99…
Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. The boxes are of two types: Type 1: each box costs c1 Taka and can hold exactly n1 marbles Type 2:…
扩展欧几里得是用于求解不定方程.线性同余方程和乘法逆元的常用算法. 下面是代码: function Euclid(a,b:int64;var x,y:int64):int64; var t:int64; begin then begin x:=;y:=;exit(a); end else begin Euclid:=Euclid(b,a mod b,x,y); t:=x;x:=y;y:=t-(a div b)*y; end; end; 下面出现了其中后两个应用.(虽然个人认为不定方程和同余方程可…