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 ...
随机推荐
- nginx完全关闭log
nginx.conf中要在http一节里面添加 access_log off; error_log off;
- mysql定时备份
1.创建备份DB的脚本 python版本的脚本 db_backup.py import os password='df' os.system('mysqldump -uroot -p{} fwss & ...
- show processlist结果筛选(转)
在MySQL里面 show variables where variable_name like '%auto%' 这条语句可以正常执行,但是 show processlist where host ...
- 数据库设计和ER模型-------之数据库系统生存期(第二章)
数据库设计 概念:开发人员利用开发环境表达用户要求.设计构造最优的数据模型,然后据此建立数据库以及其应用系统,这个过程称为数据库设计 数据库生存期 1968年首次提出“软件工程”的概念 概念:我们把数 ...
- gzip1
经过GZIP压缩后页面大小可以变为原来的30%甚至更小.要实现GZIP压缩页面需要浏览器和服务器共同支持, 实际上就是服务器压缩,传到浏览器后浏览器解压并解析.浏览器那边不需要我们担心,因为现在绝大多 ...
- MySQL配置文件以及服务的开启关闭重启
linux系统中,配置文件路径一般为/etc/my.cnf [root@host ~]# mysql --help|grep my.cnf order of ...
- Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean)
eclipse在使用maven的tomcat控件编译java程序时,报错 Failed to execute goal org.apache.maven.plugins:maven-clean-plu ...
- xml文件中的${}
看到了${}这样的表达式,脑海里面第一印象是不是我们jsp中的EL表达式?! 哈哈... 不过,这个真不是EL表达式,Spring提供了自己的EL表达式,可是它的格式是#{} so.... ${key ...
- CKEditor 5
1.官网 https://ckeditor.com/ckeditor-5/download/ 2.
- bootsrap Collapse用法
collapse用处还是挺多的. 使用方法先看看bootstrap官方文档:https://v3.bootcss.com/javascript/#collapse You can use a link ...