hdu2669-Romantic-(扩展欧几里得定理)
Romantic
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10883 Accepted Submission(s):
4610
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.
Each case
two nonnegative integer a,b (0<a, b<=2^31)
are more answers than the X smaller one will be choosed. If no answer put
"sorry" instead.
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
// ax + by = gcd(a,b)
ll exgcd(ll a, ll b, ll &x, ll &y)//扩展欧几里德定理
{
if(b==)//终有一次a%b传进来是0,递归出口
{
x=;y=;
return a;
}
ll q=exgcd(b,a%b,y,x);
//最终递归出来,y1=1,x1=0
y=y-(a/b)*x;
//后面的y相当于下一个递归的x2,x相当于下一个递归的y2,符合推导公式
//x1=y2; y1=x2-[a/b]*y2;
return q;
} int main()
{
ll a,b;
while(scanf("%lld %lld",&a,&b)!=EOF)
{
ll x,y;
ll gcd=exgcd(a,b,x,y);
if(gcd==)
{
while(x<)
{
x=x+b;
y=y-a;
}
printf("%lld %lld\n",x,y);
}
else printf("sorry\n");
}
return ;
}
hdu2669-Romantic-(扩展欧几里得定理)的更多相关文章
- HDU 2669 Romantic (扩展欧几里得定理)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- poj1061-青蛙的约会-(贝祖定理+扩展欧几里得定理+同余定理)
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions:132162 Accepted: 29199 Descripti ...
- poj 1061(扩展欧几里得定理求不定方程)
两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特 ...
- hdu_2669 Romantic(扩展欧几里得)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2669 Romantic Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 2669 Romantic 扩展欧几里得
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisf ...
- hdu3579-Hello Kiki-(扩展欧几里得定理+中国剩余定理)
Hello Kiki Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu1573-X问题-(扩展欧几里得定理+中国剩余定理)
X问题 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- poj2115-Looooops-(扩展欧几里得定理)
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions:33752 Accepted: 9832 Descri ...
- 扩展欧几里得 求ax+by == n的非负整数解个数
求解形如ax+by == n (a,b已知)的方程的非负整数解个数时,需要用到扩展欧几里得定理,先求出最小的x的值,然后通过处理剩下的区间长度即可得到答案. 放出模板: ll gcd(ll a, ll ...
随机推荐
- CS229 4.Logistic Regression
- oi造数据
#include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #includ ...
- MySQL ERROR 1300 (HY000): Invalid utf8 character string
load data报错 原因:原始数据含有 中文\中文 这样的带斜线的字符串. 解决方案:导出的时候替换 replace(d.role_name,'\\','.' ),这样导入时候就不用处理了
- html中header,footer分别固定在顶部和底部
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>page01</title> 5 <styl ...
- #151: 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字、1位识别码和3位分隔符,其规定格式如“x-xxx-x
试题描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字.1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”是分隔符(键盘上的减号),最后一位 ...
- eclipse windowbuilder palette 空白
今天在 eclipse 上安装了 windowbuilder 插件,但是 palette 一直是空白的,不能放控件. 版本 eclipse 4.9.0, windowbuilder 1.9.0. 经过 ...
- Mac技巧之苹果电脑Mac OS X系统自带的鼠标所在点颜色RGB值查看工具:数码测色计
转自http://www.mac52ipod.cn/post/show-mouse-point-rgb-color-by-apple-mac-os-x-tool.php
- Windows下python库的常用安装方法
目录: 1.pip安装(需要pip) 2.通过下载whl文件安装(需要pip) 3.在pythn官网下载安装包安装(不需要pip) 方法一:pip安装. 这是最 ...
- 【Social Listening实战】当数据分析遭遇心理动力学:用户深层次的情感需求浮出水面
本文转自知乎 作者:苏格兰折耳喵 ----------------------------------------------------- 本文篇幅较长,分为五部分,在中间部分有关于心理分析工具的介 ...
- Promise笔记
参考:阮一峰es6(http://es6.ruanyifeng.com/#docs/promise) 时间:2018-07-03 类型:个人笔记 解决的问题:异步编程的一种解决方案. 定义:Promi ...