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

Sample Output

2 -3
sorry
7 -3
 

裸的扩展欧几里得

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int exgcd(int a,int b,int &x,int &y){
if(b==){
x=;y=;
return a;
}
int res=exgcd(b,a%b,x,y);
int t=x;x=y;y=t-a/b*y;
return res;
}
int main(){
int a,b,x,y;
while(scanf("%d%d",&a,&b)!=EOF)
{
int g=exgcd(a,b,x,y);
if(%g)
printf("sorry\n");
else{
while(x<){x+=b;y-=a;}
printf("%d %d\n",x,y);
}
}
return ;
}

HDU2669 Romantic的更多相关文章

  1. HDU2669 Romantic 扩展欧几里德 对我来说有陷阱

    这道题对我来说有陷阱虽说是赤果果的扩展欧几里德,看样子基本攻还是不够哈,基本功夫一定要好,准备每天上那种洗脑课时分  多看看数论书,弥补一下 自己 狗一样的基础, 这道题用到了一个性质: 对于不定整数 ...

  2. hdu 2669 Romantic

    Romantic Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  3. hdu 2669 Romantic (乘法逆元)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. 『摄影欣赏』16幅 Romantic 风格照片欣赏【组图】

    今天,我们将继续分享人类情感的系列文章.爱是人类最重要的感觉,也可能是各种形式的艺术(电影,音乐,书,画等)最常表达的主题 .这里有40个最美丽的爱的照片,将激励和给你一个全新的视觉角度为这种情绪.我 ...

  5. HDU 4901 The Romantic Hero

    The Romantic Hero Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %I64d & %I64u D ...

  6. HDU4901 The Romantic Hero 计数DP

    2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...

  7. HDU 4901 The Romantic Hero (计数DP)

    The Romantic Hero 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/E Description There is ...

  8. Romantic(裸扩展欧几里德)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. HDU 4901 The Romantic Hero(二维dp)

    题目大意:给你n个数字,然后分成两份,前边的一份里面的元素进行异或,后面的一份里面的元素进行与.分的时候依照给的先后数序取数,后面的里面的全部的元素的下标一定比前面的大.问你有多上种放元素的方法能够使 ...

随机推荐

  1. python__基础 : sys模块: sys.argv与sys.path

    sys模块中的 argv 保存的是当你运行一个py文件的时候给他传递进去的参数,如: import sys a = sys.argv print(a) # 当在命令行中调用这个py文件: > p ...

  2. C语言真正的编译过程(4个步骤~~预编译,编译,汇编,连接)

    转载自:https://www.cnblogs.com/wuyouxiaocai/p/5701088.html#commentform 说实话,很多人做了很久的C/C++,也用了很多IDE,但是对于可 ...

  3. C++ 十进制 八进制 十六进制的转换和关系

    在默认情况下,cout以十进制格式显示整数,而不管这些整数在程序中是如何书写的.如下面的程序所示: #include<iostream> using namespace std; #inc ...

  4. [Codeforces958C2]Encryption (medium)(区间DP)

    Description 题目链接 Solution 显然的区间DP,正常想法f[i][j]表示前i个数分成j块,每次在i前找一个k使得balala,然而常规打法会超时 我们发现,对于i前面的所有点,他 ...

  5. HNU暑假训练第一场C.Ninja Map

    一.题目大意 Intersections of Crossing Path City are aligned to a grid. There are N east-west streets whic ...

  6. urllib使用四--urlencode,urlparse,

    urllib.urlencode 把字典数据转换为URL编码 # -*- coding: cp936 -*- import urllib params = {'score':100,'name':'爬 ...

  7. ASP.NET 使用 MySQL

    基本是通用的 C#与MySQL的交互, 先添加MySQL.Data.dll(位于MySQL安装目录下的Connector NET 8.0\Assemblies${version}目录下)引用, 之后代 ...

  8. 设置默认以管理员运行的WinForm

    右键工程名, 属性; 选择"安全性"; 勾选"启用ClickOnce安全设置"与"这是完全可信的应用程序"; 退出该页面, app.mani ...

  9. python基础之正则表达式爬虫应用,configparser模块和subprocess模块

    正则表达式爬虫应用(校花网) 1 import requests 2 import re 3 import json 4 #定义函数返回网页的字符串信息 5 def getPage_str(url): ...

  10. 13 Django组件-cookie与session

    会话跟踪技术 1 什么是会话跟踪技术 我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应.例如你给10086打个电话,你就是客户端,而10 ...