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 Xa + Yb = 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

直接用拓展欧几里得,但是注意Find the nonnegative integer X and integer Y,f there are more answers than the X smaller one will be choosed.

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
typedef __int64 ll;
typedef long double ld;
const ll mod=1e9+7;
using namespace std;
const double pi=acos(-1.0);
ll exgcd(ll a,ll b,ll &x,ll &y)//x,y在输入的时候不用定义
{
int d, t;
if(b==0)
{
x=1;
y=0;
return a;
}else
{
d = exgcd(b, a % b,x,y);
t = x - a / b * y;
x = y;
y = t;
return d;
}
}
int main()
{
ll a,b,r,x,y;
while(~scanf("%I64d%I64d",&a,&b))
{
r=exgcd(a,b,x,y);
if(r!=1)
pf("sorry\n");
else
{
while(x<0)
{
x+=b;
y-=a;
}
pf("%I64d %I64d\n",x,y);
} }
return 0;
}

J - Romantic的更多相关文章

  1. HDU 4901 The Romantic Hero

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

  2. HDU4901 The Romantic Hero 计数DP

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

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

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

  4. HDU 4901 The Romantic Hero 题解——S.B.S.

    The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  5. HDOJ 4901 The Romantic Hero

    DP....扫两次合并 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  6. 【Java并发编程实战】-----“J.U.C”:CAS操作

    CAS,即Compare and Swap,中文翻译为"比较并交换". 对于JUC包中,CAS理论是实现整个java并发包的基石.从整体来看,concurrent包的实现示意图如下 ...

  7. 【Java并发编程实战】-----“J.U.C”:Exchanger

    前面介绍了三个同步辅助类:CyclicBarrier.Barrier.Phaser,这篇博客介绍最后一个:Exchanger.JDK API是这样介绍的:可以在对中对元素进行配对和交换的线程的同步点. ...

  8. 【Java并发编程实战】-----“J.U.C”:CountDownlatch

    上篇博文([Java并发编程实战]-----"J.U.C":CyclicBarrier)LZ介绍了CyclicBarrier.CyclicBarrier所描述的是"允许一 ...

  9. 【Java并发编程实战】-----“J.U.C”:CyclicBarrier

    在上篇博客([Java并发编程实战]-----"J.U.C":Semaphore)中,LZ介绍了Semaphore,下面LZ介绍CyclicBarrier.在JDK API中是这么 ...

随机推荐

  1. [数据结构与算法分析(Mark Allen Weiss)]不相交集 @ Python

    最简单的不相交集的实现,来自MAW的<数据结构与算法分析>. 代码: class DisjSet: def __init__(self, NumSets): self.S = [0 for ...

  2. 读懂isi get的结果

    你想知道的一切,在这里: Isi Get & Set https://community.emc.com/community/products/isilon/blog/2018/02/21/i ...

  3. CDH:cdh5环境搭建

    安装环境三台centos7 vmw: cdh- 192.168.0.141 [主节点] cdh- 192.168.0.142 [从节点] cdh- 192.168.0.143 [从节点] 1)[各节点 ...

  4. Java access to the Domino Objects, Part 1

    From: https://www.ibm.com/developerworks/lotus/library/ls-Java_access_pt1/index.html Overview Java a ...

  5. Redis深入之对象

    Redis对象系统 前面介绍了Redis用到的全部主要数据结构,如简单动态字符串(SDS).双端链表.字典.压缩列表.整数集合等 Redis并没有直接使用这些数据结构来实现键值对数据库.而是基于这些数 ...

  6. Windows平台下tomcat 性能调优

    Tomcat 线程查看工具: https://blog.csdn.net/jrainbow/article/details/49026365 16G内存 Tomcat并发优化.内存配置.垃圾回收.宕机 ...

  7. hadoop权威指南学习(一) - 天气预报MapReduce程序的开发和部署

    看过Tom White写的Hadoop权威指南(大象书)的朋友一定得从第一个天气预报的Map Reduce程序所吸引, 殊不知,Tom White大牛虽然在书中写了程序和讲解了原理,但是他以为你们都会 ...

  8. Centos7安装Tomcat并部署DubboAdmin的War包并配置自动启动

    一.安装过程 1.打开官网,在左侧选择要下载的版本,比如下下载Tomcat8:https://tomcat.apache.org/download-80.cgi 2.找到tar.gz的下载地址:htt ...

  9. M1 卡技术规范

    射频卡简单来讲就是卡的一种工作方式,通过感应的方式来工作,也能够把全部的感应卡都统称为射频卡. IC卡的范围比較广.芯片外露的接触式IC卡.芯片内置的感应式IC卡和双界面IC卡都可统称为IC卡.IC卡 ...

  10. tmux的复制粘贴

    tmux有面板的概念,这导致普通终端下的ctrl+shift+C的模式复制出来的文本会串行.如果面板只有一列当然没有问题,但当面板有多列时,复制就会出问题.于是tmux提出了类似vim的复制模式.因此 ...