#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #define ll long long using namespace std; ll n,p; void exgcd(ll a,ll b,ll &x,ll &y) { if(!b) { x=1;y=0; return; } exgcd(b,a%b,x,y); ll tmp=x; x=y; y=tmp-a/b*y; } int main() { scanf("%lld%lld",&n,&p); ll x=0,y=0; exgcd(n,p,x,y); x=(x%p+p)%p; printf("%lld\n",x); return 0; }
原文地址:https://www.cnblogs.com/water-radish/p/9280549.html
时间: 2024-10-07 20:51:19