Last active
November 20, 2019 11:30
-
-
Save latte0119/c967eed6ee1718d2d60ea0fd143c10e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int extgcd(int a,int b,int &x,int &y){ | |
if(b==0){ //a*1+b*0=a なので! | |
x=1; | |
y=0; | |
return a; | |
} | |
int g=extgcd(b,a%b,x,y); | |
int next_x,next_y; | |
next_x=y; | |
next_y=x-(a/b)*y; | |
x=next_x; | |
y=next_y; | |
return g; | |
} | |
int main(){ | |
int a=12; | |
int b=18; | |
int x,y; | |
int g=extgcd(a,b,x,y); | |
cout<<g<<endl; //6 | |
cout<<x<<" "<<y<<endl; //-1 1 | |
cout<<a*x+b*y<<endl; //6 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int extgcd(int a,int b,int &x,int &y){ | |
if(b==0){ //a*1+b*0=a なので! | |
x=1; | |
y=0; | |
return a; | |
} | |
int g=extgcd(b,a%b,x,y); | |
swap(x,y); | |
int next_x,next_y; | |
next_x=x; | |
next_y=y-(a/b)*x; | |
x=next_x; | |
y=next_y; | |
return g; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int extgcd(int a,int b,int &x,int &y){ | |
if(b==0){ //a*1+b*0=a なので! | |
x=1; | |
y=0; | |
return a; | |
} | |
int g=extgcd(b,a%b,x,y); | |
swap(x,y); | |
//next_x=x; | |
//next_y=y-(a/b)*x; | |
y-=(a/b)*x; | |
return g; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int extgcd(int a,int b,int &x,int &y){ | |
if(b==0){ //a*1+b*0=a なので! | |
x=1; | |
y=0; | |
return a; | |
} | |
//int g=extgcd(b,a%b,x,y); | |
//swap(x,y); | |
int g=extgcd(b,a%b,y,x); | |
//next_x=x; | |
//next_y=y-(a/b)*x; | |
y-=(a/b)*x; | |
return g; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment