hdu_2669 Romantic(扩展欧几里得)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2669
Romantic
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4179 Accepted Submission(s): 1745
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)
10 44
34 79
sorry
7 -3
#include<cstdio>
#include<iostream>
using namespace std;
#define ll long long
ll gcd(ll a, ll b)
{
return b==? a: gcd(b,a%b);
}
ll extend_gcd(ll x, ll y, ll &a, ll &b)
{
if(y==){
a = ;
b = ;
return x;
}
ll d = extend_gcd(y, x%y, b, a);
b = b - (x/y)*a;
return d;
}
int main()
{
ll a, b;
while(~scanf("%I64d%I64d",&a,&b))
{
if(gcd(a,b)!=)
puts("sorry");
else {
ll x, y;
extend_gcd(a,b,x,y);
while(x<=){
x+=b;
y-=a;
}
printf("%I64d %I64d\n",x,y);
}
}
return ;
}
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 扩展欧几里得
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisf ...
- hdu2669-Romantic-(扩展欧几里得定理)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- UVA 12169 Disgruntled Judge 枚举+扩展欧几里得
题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...
- UVA 10090 Marbles 扩展欧几里得
来源:http://www.cnblogs.com/zxhl/p/5106678.html 大致题意:给你n个球,给你两种盒子.第一种盒子每个盒子c1美元,可以恰好装n1个球:第二种盒子每个盒子c2元 ...
- POJ 1061 青蛙的约会 扩展欧几里得
扩展欧几里得模板套一下就A了,不过要注意刚好整除的时候,代码中有注释 #include <iostream> #include <cstdio> #include <cs ...
- 【64测试20161112】【Catalan数】【数论】【扩展欧几里得】【逆】
Problem: n个人(偶数)排队,排两行,每一行的身高依次递增,且第二行的人的身高大于对应的第一行的人,问有多少种方案.mod 1e9+9 Solution: 这道题由1,2,5,14 应该想到C ...
- poj 2891 扩展欧几里得迭代解同余方程组
Reference: http://www.cnblogs.com/ka200812/archive/2011/09/02/2164404.html 之前说过中国剩余定理传统解法的条件是m[i]两两互 ...
随机推荐
- [array] leetcode - 48. Rotate Image - Medium
leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...
- 使用VMware安装linux虚拟机以及相关配置
前言 使用VMware安装虚拟机这个一般都知道,操作简单.而本文主要讲使用虚拟机的后续相关配置.并记录使用过程中遇到的问题以及一些技巧.本篇文章以后回持续更新的... 安装包准备 VM:12 Linu ...
- treeview插件使用:根据子节点选中父节点
鄙人公司没有专门的前端,所以项目开发中都是前后端一起抡.最近用bootstrap用的比较频繁,发现bootstrap除了框架本身的样式组件外,还提供了多种插件供开发者选择.本篇博文讲的就是bootst ...
- sql经典试题
1.一道SQL语句面试题,关于group by表内容:2005-05-09 胜2005-05-09 胜2005-05-09 负2005-05-09 负2005-05-10 胜2005-05-10 负2 ...
- Jmeter+Ant+Jenkins接口自动化测试(一)_环境部署
前言: 2017年最后一个月份,今天抽出时间把之前的一些记录分享出来,也为今年画上个简单的句号吧,无论好与坏,无论成功与失败,简单的记忆,不要留下点点空白. 特别提示: 知识是用来分享的,但是也要尊重 ...
- 安装spark单机环境
(假定已经装好的hadoop,不管你装没装好,反正我是装好了) 1 下载spark安装包 http://spark.apache.org/downloads.html 下载spark-1.6.1-bi ...
- php逐行读取txt文件写入数组的方法
使用说明: 采用fopen 方法,逐行读取数据,并使用feof($fp) 判断是否文件截止,最后通过filter() 方法,去除空白行,得到所需数据 $file = fopen("user ...
- Python的变量和常量
解释器执行Python的过程: (python3,c:/test.py) 1:启动python解释器(内存中). 2:将c:/test.py内容从硬盘读到内存中(这一步和文本编辑器是一样的). 3 ...
- jsonp及cors
一. jsonp实现原理是利用script标签可以获取不同源资源的特点,来达到跨域访问某个资源的目的.具体行为如下: 创建一个script标签,将请求地址写入它的src属性,将这个script外链插入 ...
- ul li内的文字水平居中显示
head><style rel="stylesheet" type="text/css" >#top{height:140px;}#top u ...