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. 

InputThe input contains multiple test cases. 
Each case two nonnegative integer a,b (0<a, b<=2^31) 
Outputoutput 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
这个题目的坑就在 输出上,,x必须为正数,,y必须为负数,想想也很有道理 因为 X*a + Y*b = 1. a,b,都是大于1 的所以x和Y要有一个小于0,一个大于0,结果才会等于1
//直接用拓展欧几里得公式求出x和y,再除以a,b的最大公约数q,如果依然是整数,则输出,否则,x+=b,y-=a,再判断
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll x,y; ll exgcd(ll a,ll b){
if(b==) {
x=;
y=;
return a;
}
ll r=exgcd(b,a%b);
ll t=y;
y=x-(a/b)*y;
x=t;
return r;
} int main(){
ll a,b;
while(scanf("%lld%lld",&a,&b)!=EOF)
{
ll r=exgcd(a,b);
if(r!=){
puts("sorry");
continue ;
}
ll x1=x;
ll y1=y;
x1=(x1+b)%b;
// while(x1<0){
// x+=b/r;
// }
// while(y1>0){
// y1-=a/r;
// }
y1=(y1-a)%a; printf("%lld %lld\n",x1,y1);
}
return ;
}
												

D - Romantic的更多相关文章

  1. hdu 2669 Romantic

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

  2. hdu 2669 Romantic (乘法逆元)

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

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

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

  4. HDU 4901 The Romantic Hero

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

  5. HDU4901 The Romantic Hero 计数DP

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

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

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

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

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

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

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

  9. hdu_2669 Romantic(扩展欧几里得)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2669 Romantic Time Limit: 2000/1000 MS (Java/Others)  ...

  10. Romantic(hdu2699+欧几里德)

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

随机推荐

  1. 为arm-unknown-linux-gnueabi-gcc工具链添加常用库(zlib、libpng、libjpeg、libtiff、libtool)(转载)

    主机环境: RHEL6.0 kernel 2.6.32-220.2.1.el6.i686 gcc-4.4.6   1.zlib http://sourceforge.net/projects/libp ...

  2. Linux基本操作 ------ 文件处理命令

    显示目录文件 ls //显示当前目录下文件 ls /home //显示home文件夹下文件 ls -a //显示当前目录下所有文件,包括隐藏文件 ls -l //显示当前目录下文件的详细信息 ls - ...

  3. python set() leetcode 签到820. 单词的压缩编码

    题目 给定一个单词列表,我们将这个列表编码成一个索引字符串 S 与一个索引列表 A. 例如,如果这个列表是 ["time", "me", "bell& ...

  4. 文件映射(Windows核心编程)

    映射内存的可执行文件和dll 当一个线程调用CreateProcess的时候,系统会执行以下步骤: 系统会先确定CreateProcess所指定的可执行文件的所在位置.如果找不到文件,那么Create ...

  5. OpenCV-Python 直方图-4:直方图反投影 | 二十九

    目标 在本章中,我们将学习直方图反投影. 理论 这是由Michael J. Swain和Dana H. Ballard在他们的论文<通过颜色直方图索引>中提出的. 用简单的话说是什么意思? ...

  6. 负载均衡器nginx和ribbon区别

    1,nginx 是服务器端的负载均衡器,所有请求发送到nginx之后,nginx通过反向代理的功能分发到不同的服务器,做负载均衡 2,ribbon是客户端的负载均衡器,他是通过将eureka注册中心上 ...

  7. Ruby学习计划-(0)前言

      前言   接触过的编程语言现在来说有C.C++.Java.Object-C.Swift.这几门语言中最熟悉的就是oc了,毕竟靠他吃饭,对于其他几门语言都是初入门径而已,由于本身一直从事iPhone ...

  8. 1011 World Cup Betting (20 分)

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  9. Altium 分形天线设计

    Altium 分形天线设计 程序运行界面 Cantor三分集 Koch雪花 Sierpinski垫片 源代码: Iter_Num = 4     'diedai PI = 3.1415926 Call ...

  10. CAS单点登录系列之极速入门于实战教程(4.2.7)

    @ 目录 一. SSO简介 1.1 单点登录定义 1.2 单点登录角色 1.3 单点登录分类 二. CAS简介 2.1 CAS简单定义 2.2 CAS体系结构 2.3 CAS原理 三.CAS服务端搭建 ...