Problem 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.

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


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 51 10 44 34 79

Sample Output
2 -3
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <cmath>  
#include <string>  
#include <vector>  
#include <stack>  
#include <queue>  
#include <algorithm>  
using namespace std;

typedef long long LL;

LL exgcd(LL a, LL b, LL &x, LL &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	LL ans = exgcd(b, a%b, x, y);
	LL t = x;
	x = y;
	y = t - a / b*y;
	return ans;

LL cal(LL a, LL b, LL c) {
	LL x, y;
	LL gcd = exgcd(a, b, x, y);
	if (c%gcd) {
		return -1;
	x *= c / gcd;
	b /= gcd;
	b = abs(b);
	LL ans = x%b;
	if (ans <= 0)ans += b;
	return ans;

int main() {
	LL a, b, A, B, t;
	while (cin >> a >> b) {
		LL ans = cal(a, b, 1);
		if(ans==-1)	cout << "sorry\n";
		else cout << ans << " " << (1 - ans*a) / b << endl;

sorry7 -3

The Romantic Hero


Problem DescriptionnThere is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil. Also, this devil is looking like a very cute Loli.nnYou may wonder why this country has such an interesting tradition? It has a very long story, but I won't tell you :).nnLet us continue, the party princess's knight win the algorithm contest. When the devil hears about that, she decided to take some action.nnBut before that, there is another party arose recently, the 'MengMengDa' party, everyone in this party feel everything is 'MengMengDa' and acts like a 'MengMengDa' guy.nnWhile they are very pleased about that, it brings many people in this kingdom troubles. So they decided to stop them.nnOur hero z*p come again, actually he is very good at Algorithm contest, so he invites the leader of the 'MengMengda' party xiaod*o to compete in an algorithm contest.nnAs z*p is both handsome and talkative, he has many girl friends to deal with, on the contest day, he find he has 3 dating to complete and have no time to compete, so he let you to solve the problems for him.nnAnd the easiest problem in this contest is like that:nnThere is n number a_1,a_2,...,a_n on the line. You can choose two set S(a_s1,a_s2,..,a_sk) and T(a_t1,a_t2,...,a_tm). Each element in S should be at the left of every element in T.(si < tj for all i,j). S and T shouldn't be empty.nnAnd what we want is the bitwise XOR of each element in S is equal to the bitwise AND of each element in T.nnHow many ways are there to choose such two sets? You should output the result modulo 10^9+7.n nnInputnThe first line contains an integer T, denoting the number of the test cases.nFor each test case, the first line contains a integers n.nThe next line contains n integers a_1,a_2,...,a_n which are separated by a single space.nnn<=10^3, 0 <= a_i <1024, T<=20.n nnOutputnFor each test case, output the result in one line.n nnSample Inputn2n3n1 2 3n4n1 2 3 3n nnSample Outputn1 n4n


  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他