/*扩展欧几里得 ax%b==1 -> ax-by==1 求不定方程的一组解 使x为最小正整数解 */#include#include #include using namespace std;int x,y,gcd;int Extend(int a,int b){ if(b==0) { x=1;y=0; gcd=a; } else { Extend(b,a%b); int tmp=x; x=y; y=tmp-a/b*y; }}int main(){ int a,b; scanf("%d%d",&a,&b); Extend(a,-b); x=x*(1/gcd); if(x<0)while(x<0)x=x+b; else while(x-b>0)x=x-b; printf("%d\n",x); return 0;}