hdu 2669(扩展欧几里得)
Romantic
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4400 Accepted Submission(s): 1852
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)
nonnegative integer X and integer Y, if there are more answers than the
X smaller one will be choosed. If no answer put "sorry" instead.
10 44
34 79
sorry
7 -3
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL; LL extend_gcd(LL a,LL b,LL &x,LL &y){
if(!b){
x=,y = ;
return a;
}else{
LL x1,y1;
LL d = extend_gcd(b,a%b,x1,y1);
x = y1;
y = x1 - a/b*y1;
return d;
}
}
int main()
{
LL a,b,x,y;
while(~scanf("%lld%lld",&a,&b)){
LL d = extend_gcd(a,b,x,y);
if(d!=){
printf("sorry\n");
}else{
x = (x%b+b)%b;
y = (-a*x)/b;
printf("%lld %lld\n",x,y);
}
}
return ;
}
hdu 2669(扩展欧几里得)的更多相关文章
- hdu 2669 扩展欧几里得(裸)
#include<stdio.h> #include<iostream> #define ll __int64 ll gcd(ll a,ll b,ll &x,ll &a ...
- HDU 5114 扩展欧几里得
题目大意:给你两个球的坐标 他们都往(1, 1)这个方向以相同的速度走,问你他们在哪个位置碰撞. 思路:这种题目需要把x方向和y方向分开来算周期,两个不同周期需要用扩展欧几里得来求第一次相遇. #in ...
- HDU 4180 扩展欧几里得
RealPhobia Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU RSA 扩展欧几里得
Problem Description RSA is one of the most powerful methods to encrypt data. The RSA algorithm is de ...
- 扩展欧几里得 hdu 1576
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 不知道扩展欧几里得的同学可以参考:https://blog.csdn.net/zhjchengf ...
- hdu 5512 Pagodas 扩展欧几里得推导+GCD
题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 2000 ...
- hdu 1573 A/B (扩展欧几里得)
Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973)= 1). Input 数据的第一行 ...
- hdu 1576 A/B 【扩展欧几里得】【逆元】
<题目链接> <转载于 >>> > A/B Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)( ...
- [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)
Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...
随机推荐
- Essential C++ 3.1 节的代码练习——哨兵方式
#include "IncrementArray.hpp" template <typename element> element *find_address(elem ...
- A1065 A+B and C (64bit) (20)(20 分)
A1065 A+B and C (64bit) (20)(20 分) Given three integers A, B and C in [-2^63^, 2^63^], you are suppo ...
- (洛谷)P1019 单词接龙
题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的"龙"(每个单词都最多在"龙" ...
- adaboost python实现小样例
元算法是对其他算法进行组合的一种方式.单层决策树实际上是一个单节点的决策树.adaboost优点:泛化错误率低,易编码,可以应用在大部分分类器上,无参数调整缺点:对离群点敏感适用数据类型:数值型和标称 ...
- 谋哥:App推广最有效的是自推广
[谋哥每天一原创,第一百五十二篇] 目前市场上,各类App已经覆盖到所有你能想到的领域,并且各个山头也被占得差不多了,网上 的说法就是布局已经完成.如果你想现在再插那么一杠子进去,就得看你的真本事了, ...
- PostgreSQL查看索引的使用情况
查看某个表的索引使用情况 select relname, indexrelname, idx_scan, idx_tup_read, idx_tup_fetch from pg_stat_user_i ...
- Gym100623A Access Control Lists
Gym 100623A Access Control Lists 这个题很sb啊,就是去设置个交换机 我们可以给一个IP进行设置,也可以对一个网段就行设置,但是IP是优于网段的,比如样例的第一个 网段 ...
- linux VIM编辑器常用指令
一般模式 查看文本-移动光标 [Ctrl] + [f] 屏幕『向前』移动一页 [Ctrl] + [b] 屏幕『向后』移动一页 n<space> 按下数字后再按空格键,光标会向右移动这一 ...
- android AsyncTask使用限制
由于AsyncTask内部是使用线程池(ThreadPoolExecutor)来管理要处理的任务的,所以AsyncTask的弊端就非常明确了:要extcute的任务数量超过线程池最大容量时,必然会报错 ...
- iptables + Denyhost抵御暴力破解
使用iptables 现在每分钟连接ssh的次数 #允许本地环回接口访问 1 iptables -A INPUT -i lo -j ACCEPT #对已经建立的所有链接都放行 1 iptabl ...