标签:
线性方程
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
#include <iostream>
#include <cstdio>
using namespace std;
void gcd(long long a,long long b,long long &d,long long &x,long long &y)
{
if(!b)
{
d=a;
x=1;
y=0;
}
else
{
gcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
int main()
{
long long a,b;
while(scanf("%lld%lld",&a,&b)==2)
{
long long d,x,y;
gcd(a,b,d,x,y);
if(d==1)
{
while(x<0)
{
x=x+b;
y=y-a;
}
printf("%lld %lld\n",x,y);
}
else
printf("sorry\n");
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/xl1164191281/p/4748741.html