51node1256 乘法匿元(扩展欧几里得)
#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<<endl; return 0; }
为保持手感