HDU 2669 Romantic

大明宫

关注

阅读 40

2022-11-10


Description



The Sky is Sprite. 

The Birds is Fly in the Sky. 


The Wind is Wonderful. 


Blew Throw the Trees 


Trees are Shaking, Leaves are Falling. 


Lovers Walk passing, and so are You. 


................................Write in English class by yifenfei 



 



Girls are clever and bright. In HDU every girl like math. Every girl like to solve math problem! 


Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisfy X*a + Y*b = 1. If no such answer print "sorry" instead. 



Input


The input contains multiple test cases. 
Each case two nonnegative integer a,b (0<a, b<=2^31) 


Output


output nonnegative integer X and integer Y, if there are more answers than the X smaller one will be choosed. If no answer put "sorry" instead. 


Sample Input


77 5110 44
34 79


Sample Output


2 -3sorry

7 -3


exgcd的简单题

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define fi first
#define se second
#define mp(i,j) make_pair(i,j)
#define pii pair<string,string>
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 0x7FFFFFFF;
const int mod = 9973;
const int N = 5e3 + 10;
const int read()
{
char ch = getchar();
while (ch<'0' || ch>'9') ch = getchar();
int x = ch - '0';
while ((ch = getchar()) >= '0'&&ch <= '9') x = x * 10 + ch - '0';
return x;
}
LL a, b;

LL exgcd(LL a, LL b, LL &x, LL &y)
{
if (!b) { x = 1, y = 0; return a; }
LL g = exgcd(b, a%b, x, y);
LL z = x - a / b * y;
x = y; y = z; return g;
}

int main()
{
while (scanf("%lld%lld%", &a, &b) != EOF)
{
LL x, y, g = exgcd(a, b, x, y);
if (g > 1) { printf("sorry\n"); continue; }
x = (x % b + b) % b;
y = (1 - a * x) / b;
printf("%lld %lld\n", x, y);
}
return 0;
}



精彩评论(0)

0 0 举报