HDU2669 Romantic
Description
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
Each case two nonnegative integer a,b (0<a, b<=2^31)
Output
than the X smaller one will be choosed. If no answer put "sorry"
instead.
Sample Input
10 44
34 79
Sample Output
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的更多相关文章
- HDU2669 Romantic 扩展欧几里德 对我来说有陷阱
这道题对我来说有陷阱虽说是赤果果的扩展欧几里德,看样子基本攻还是不够哈,基本功夫一定要好,准备每天上那种洗脑课时分 多看看数论书,弥补一下 自己 狗一样的基础, 这道题用到了一个性质: 对于不定整数 ...
- hdu 2669 Romantic
Romantic Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- hdu 2669 Romantic (乘法逆元)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 『摄影欣赏』16幅 Romantic 风格照片欣赏【组图】
今天,我们将继续分享人类情感的系列文章.爱是人类最重要的感觉,也可能是各种形式的艺术(电影,音乐,书,画等)最常表达的主题 .这里有40个最美丽的爱的照片,将激励和给你一个全新的视觉角度为这种情绪.我 ...
- HDU 4901 The Romantic Hero
The Romantic Hero Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %I64d & %I64u D ...
- HDU4901 The Romantic Hero 计数DP
2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...
- HDU 4901 The Romantic Hero (计数DP)
The Romantic Hero 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/E Description There is ...
- Romantic(裸扩展欧几里德)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 4901 The Romantic Hero(二维dp)
题目大意:给你n个数字,然后分成两份,前边的一份里面的元素进行异或,后面的一份里面的元素进行与.分的时候依照给的先后数序取数,后面的里面的全部的元素的下标一定比前面的大.问你有多上种放元素的方法能够使 ...
随机推荐
- 可以字符串string转化成list,tuple,dict的eval()方法
功能:将字符串str当成有效的表达式来求值并返回计算结果. 语法: eval(source[, globals[, locals]]) -> value 参数: source:一个Python表 ...
- PHP.20-图片上传下载
图片上传下载 思路: 1.创建图片上传的存放目录 /uploads/ 2.index.php //浏览页面,提供上传表单 上传表单:文件上传必须使用enctype="multipart/fo ...
- PHP.14-图片处理类
图片处理类 test.php <?php include "images.class.php"; $image=new Image("./images/" ...
- android onNewIntent 为什么要在onNewIntent的时候要显示的去调用setIntent
原因: 当调用到onNewIntent(intent)的时候,需要在onNewIntent() 中使用setIntent(intent)赋值给Activity的Intent.否则,后续的getInte ...
- 剑指Offer - 九度1519 - 合并两个排序的链表
剑指Offer - 九度1519 - 合并两个排序的链表2013-11-30 22:04 题目描述: 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则.(hi ...
- 《Cracking the Coding Interview》——第14章:Java——题目2
2014-04-26 18:44 题目:在java的try-catch-finally语句块里,如果catch里面有return语句的话,finally还会被执行吗? 解法:会. 代码: // 14. ...
- 玩转Node.js(一)
玩转Node.js(一) 在说Node.js之前,我们先来说说js,如果你也曾开发过前端,那么你一定接触到了这个叫JavaScript有趣的东西,而对于JavaScript,你只会基本的操作——为we ...
- 【Search in Rotated Sorted Array II 】cpp
题目: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would t ...
- 使用jquery validate结合zui作表单验证
1.引入jquery validate和zui <!-- jQuery (ZUI中的Javascript组件依赖于jQuery) --> <script src="${_b ...
- hnust 最小的x
问题 G: 最小的x 时间限制: 1 Sec 内存限制: 128 MB提交: 2347 解决: 1155[提交][状态][讨论版] 题目描述 TSQ对DK进行地狱式训练,找出满足下面公式的最小的x ...