1 solutions
-
0
扩展欧几里得算法
所以在交换以后,
代码实现
#include<bits/stdc++.h> using namespace std; int exgcd(int a,int b,int &x,int &y) { if(!b) { x=1,y=0; return a; } // int d=exgcd(b,a%b,y,x); //by+x(a-a/b*b)=d; //ax+b(y-a/b*x)=d //x=x y=y-a/b*x; y=y-a/b*x; return d; } int main() { int a,b; cin>>a>>b; int x,y; exgcd(a,b,x,y); cout<<(x%b+b)%b<<endl; return 0; }
- 1
Information
- ID
- 1911
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 1
- Accepted
- 1
- Uploaded By