#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long LL;
using namespace std;
void gcd(LL a,LL b,LL &d,LL &x,LL &y)
{
if(!b) {d=a;x=1;y=0;}
else {gcd(b,a%b,d,y,x);y-=x*(a/b);}
}
LL cal(int a,int m)
{
LL d,x,y;
gcd(a,m,d,x,y);
if(1%d!=0) return -1;
x*=1/d;
m=abs(m);
LL ans=x%m;
if(ans<=0) ans+=m;
return ans;
}
int main()
{
LL a,b;
while(scanf("%lld%lld",&a,&b)!=EOF)
{
int ans=cal(a,b);
if(ans==-1) printf("sorry\n");
else printf("%lld %lld\n",ans,(1-ans*a)/b);
}
return 0;
}
HDU 2669 Romantic
最新推荐文章于 2019-03-25 20:33:14 发布