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. php 操作 mysql 实现批量执行mysql语句 mysql文件

    <?php /** * 批量运行sql文件 * 正则分隔是重点 preg_split("/;[\r\n]+/", filecontent) */ $config = requ ...

  2. tcl之其他命令-eval/source

  3. 为什么 redis 单线程却能支撑高并发

    redis 和 memcached 有什么区别?redis 的线程模型是什么?为什么 redis 单线程却能支撑高并发? 这个是问 redis 的时候,最基本的问题吧,redis 最基本的一个内部原理 ...

  4. 好用的 Html、CSS、JavaScript 开源项目

    1.极简模块化前端UI框架 Layui 评分:9.3:收藏量:873 授权协议:MIT 开发语言:JavaScript.HTML/CSS 操作系统:跨平台 源码地址:https://gitee.com ...

  5. strak组件(10):批量操作

    效果图: 批量删除只是一个例子,可以根据需求定制自己想要的批量操作. 新增函数 def get_action_list(self) 钩子方法,获取要处理的批量操作的函数 def action_mult ...

  6. c++右值引用

    右值 右值是相对与左值来说的. 左值是以变量的形式存在,指向一个指定的内存,可以对它取地址.右值就是不指向任何地方,它是暂时和短命的,不能对它取地址. 右值引用 把临时的.生命周期短的值,绑定到一个变 ...

  7. [Bzoj4818]序列计数(矩阵乘法+DP)

    Description 题目链接 Solution 容斥原理,答案为忽略质数限制的方案数减去不含质数的方案数 然后矩阵乘法优化一下DP即可 Code #include <cstdio> # ...

  8. 1-Linux运维人员要求

    linux 运维: 1.linux基础操作命令2.linux基础服务搭建3.文本处理命令4.shell脚本编程 python perl php5.数据库 mysql oracle6.lvs集群 热备 ...

  9. startActivityForResult 请求码不正确

    今天遇到一个坑,就是 startActivityForResult 接收不到正确的请求码. 比如,我startActivityForResult的时候,设置的请求码是4,但是接收到的时候是100032 ...

  10. 关于 package.json 和 package-lock.json 文件说明

    package.json 在 Node.js 中,模块是一个库或框架,也是一个 Node.js 项目.Node.js 项目遵循模块化的架构,当我们创建了一个 Node.js 项目,意味着创建了一个模块 ...