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 ...
随机推荐
- Javascript函数心得
Javascript函数 Javascript函数是由事件驱动的或者当他被调用时执行的可重复使用的代码块.所以说我们光创建了函数不调用是没有啥用的,我们必须得调用它才能执行. 1.什么是函数 (1)函 ...
- tomcat和eclipse-wtp的一些配置
TOMCAT配置UTF-8 server.xml配置文件: <Connector port="8080" protocol="HTTP/1.1" conn ...
- 销售人员的分析,也可以用类似RFM的思路吗?
本文转自知乎 作者:接地气的陈老师 ————————————————————————————————————————————————————— 有同学问:“销售人员的分析,也可以用类似RFM的思路吗, ...
- Linux将某目录授权给某组里的某用户
chown -Rf 用户名:组名 目录
- php图片上传base64数据编码。
/** * base64图片上传 */ function IdImg($base64_img = ''){ $up_dir = 'upload/';//存放在当前目录的upload文件夹下 if(!f ...
- Ubuntu 安装微信
参考:https://blog.csdn.net/deeposcar/article/details/80710843
- spring data jpa update
一:在controller 加上: @Controller @RequestMapping("/user") public class UserController { @Aut ...
- [转]講講 John Carmack 的快速反平方根演算法
講講 John Carmack 的快速反平方根演算法 原地址http://213style.blogspot.com/2014/07/john-carmack.html 本篇的主題很簡單,講講怎麼快 ...
- 对象 Object
在js 中创建最简单的对象,然后给它添加属性或者方法 示例如下: var obj = new Object(); //或者 var obj = {}; obj.name = '张三'; obj.fun ...
- 500G JAVA视频网盘分享 (JEECG开源社区)
500 G JAVA视频网盘分享(JEECG开源社区) [涵盖从java入门到深入架构,Linux.云计算.分布式.大数据Hadoop.ios.Android.互联网技术应有尽有] J ...