HDU 2669 Romantic(扩展欧几里德)
题目链接: pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669
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)
77 51
10 44
34 79
2 -3
sorry
7 -3
PS:
扩展欧几里德模板题。
附:扩展欧几里德解说:http://blog.csdn.net/u012860063/article/details/39760003
代码例如以下:
#include <cstdio>
#include <cstring>
#include <cmath>
typedef __int64 LL; LL exgcd(LL a,LL b,LL &x,LL &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
LL r = exgcd(b,a%b,x,y);
LL t = x;
x = y;
y = t-a/b*y;
return r;
} int main()
{
LL a,b,x,y;
while(scanf("%I64d%I64d",&a,&b)!=EOF)
{
LL d = exgcd(a,b,x,y);
if(1%d)//不能整除
printf("sorry\n");
else
{
while(x<0)
x+=b,y-=a;
printf("%I64d %I64d\n",x,y);
}
}
return 0;
}
HDU 2669 Romantic(扩展欧几里德)的更多相关文章
- HDU 2669 Romantic 扩展欧几里德---->解不定方程
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2669 Romantic(扩展欧几里德, 数学题)
题目 //第一眼看题目觉得好熟悉,但是还是没想起来//洪湖来写不出来去看了解题报告,发现是裸的 扩展欧几里得 - - /* //扩展欧几里得算法(求 ax+by=gcd )//返回d=gcd(a,b) ...
- HDU 2669 Romantic (扩展欧几里得定理)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 2669 Romantic 扩展欧几里得
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisf ...
- HDU 2669 Romantic【扩展欧几里德】
裸的扩展欧几里德,求最小的X,X=((X0%b)+b)%b,每个X都对应一个Y,代入原式求解可得 #include<stdio.h> #include<string.h> ty ...
- hdu 2669 Romantic
Romantic Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU2669 Romantic 扩展欧几里德 对我来说有陷阱
这道题对我来说有陷阱虽说是赤果果的扩展欧几里德,看样子基本攻还是不够哈,基本功夫一定要好,准备每天上那种洗脑课时分 多看看数论书,弥补一下 自己 狗一样的基础, 这道题用到了一个性质: 对于不定整数 ...
- hdu 2669 Romantic (乘法逆元)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2669 Romantic(裸的拓展欧几里得)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
随机推荐
- CentOS下配置LVM和RAID
1.CentOS配置LVM http://www.cnblogs.com/mchina/p/linux-centos-logical-volume-manager-lvm.html http://ww ...
- 【转】js里的时间函数集
$(function(){ var mydate = new Date(); var t=mydate.toLocaleString(); $("#time").text(t); ...
- VBS脚本获取安全标识符SID(Security Identifiers)的方法
一.SID简介 SID也就是安全标识符(Security Identifiers),是标识用户.组和计算机帐户的唯一的号码.在第一次创建该帐户时,将给网络上的每一个帐户发布一个唯一的 SI ...
- hdu6060[贪心+dfs] 2017多校3
/* hdu6060[贪心+dfs] 2017多校3*/ #include <bits/stdc++.h> using namespace std; typedef long long L ...
- BZOJ 4589 Hard Nim ——FWT
[题目分析] 位运算下的卷积问题. FWT直接做. 但还是不太民白,发明者要承担泽任的. [代码] #include <cstdio> #include <cstring> # ...
- Redis的持久化——RDB
前面说到redis的三大特性:缓存.分布式内存数据库.持久化,所以今天将为大家介绍redis的两种数据持久化技术RDB和AOF, 先介绍RDB吧. 一.RDB是什么? 1.RDB全称redis dat ...
- polya burnside 专题
polya题目:uva 11077 Find the Permutationsuva 10294 Arif in DhakaLA 3641 Leonardo's Notebookuva 11077 F ...
- Min(BZOJ 1441)
题目描述 给出n个数(A1...An)现求一组整数序列(X1...Xn)使得S=A1*X1+...An*Xn>0,且S的值最小 输入 第一行给出数字N,代表有N个数 下面一行给出N个数 输出 S ...
- 图表控件Anychart常见问题
AnyChart控件是一款当前流行的数据可视化解决方案,使客户可以创建交互地.生动的图表.实时仪表和地图.同时支持Flash和HTML5显示,控件提供极好的视觉外观和配色方案能够使客户根据不同的需求设 ...
- Codeforces Round #291 (Div. 2) C. Watto and Mechanism [字典树]
传送门 C. Watto and Mechanism time limit per test 3 seconds memory limit per test 256 megabytes input s ...