HDU 2669 Romantic( 拓欧水 )
**链接:****传送门 **
题意:求解方程 X * a + Y * b = 1 的一组最小非负 X 的解,如果无解输出 "sorry"
思路:裸 exgcd
/*************************************************************************
> File Name: hdu2669.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月21日 星期日 18时34分40秒
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll exgcd(ll a,ll b,ll &x,ll &y){
if( b == 0 ){
x = 1 ; y = 0 ; return a;
}
ll d = exgcd( b , a%b , x , y );
ll tmp = x;
x = y; y = tmp - a/b*y;
return d;
}
int main(){
ll a , b , x , y;
while(~scanf("%lld%lld",&a,&b)){
ll d = exgcd( a , b , x , y);
ll c = 1;
if( c % d != 0 ) printf("sorry\n");
else{
x = x * (c/d);
x = ( x%(b/d) + b/d )%(b/d);
printf("%lld %lld\n",x,(1-a*x)/b);
}
}
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 扩展欧几里得
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisf ...
- hdu 2669 Romantic
Romantic Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 2669 Romantic(裸的拓展欧几里得)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Romantic HDU - 2669(扩欧)
#include<bits/stdc++.h> using namespace std; typedef long long LL; void gcd(LL a, LL b, LL &am ...
- 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 ...
- HDU 2669 Romantic(扩展欧几里德)
题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...
- HDU 2669 Romantic(扩展欧几里德, 数学题)
题目 //第一眼看题目觉得好熟悉,但是还是没想起来//洪湖来写不出来去看了解题报告,发现是裸的 扩展欧几里得 - - /* //扩展欧几里得算法(求 ax+by=gcd )//返回d=gcd(a,b) ...
随机推荐
- [SCOI2016]萌萌哒(倍增+并查集)
当区间\([a,b]\)和\([c,d]\)对应相等时. 我们把两个区间对应位置上的数所在并查集合并. 最后并查集的数量为\(num\)答案就是\(9*10^num\)因为是个数,不能有前置\(0\) ...
- 洛谷P1739 表达式括号匹配
题目描述 假设一个表达式有英文字母(小写).运算符(+,-,*,/)和左右小(圆)括号构成,以"@"作为表达式的结束符.请编写一个程序检查表达式中的左右圆括号是否匹配,若匹配,则返 ...
- BZOJ 2161 布娃娃 (主席树)
题面 想了一个主席树做法 我们把每个区间的两个端点拆开 对$L,R$分别从小到大排序,分别从左到右依次把对应标号的$c_{i}$插入到权值主席树里 每次查询$p_{i}$,在排序后的$L,R$数组上分 ...
- Cocos2d切换场景出现的问题-error C2653: “***”不是类或命名空间名称
1,在开头引入头文件 2,在要引入的头文件中,去除以下代码: #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #endif ...
- 完整的html+css+javascript实现跟随鼠标移动显示选中效果
1,显示效果: 2,html结构 <div class="process_list-lpu"> <div class="process_line&quo ...
- 《Python 源码剖析》之对象
py一切皆对象的实现 Python中对象分为两类: 定长(int等), 非定长(list/dict等) 所有对象都有一些相同的东西, 源码中定义为PyObject和PyVarObject, 两个定义都 ...
- mysql Access denied for user 'root'@'localhost' (using password: YES)
[现象说明] C/S程序远程訪问正常,本地訪问报下面异常 MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to h ...
- java 基本数据类型及自己主动类型提升
基本数据类型:8种 1.整型: byte 1个字节 8位 -128到127 short 2个字节 16位 -2^15到(2^15)-1 int 4个字节 32 ...
- Ubuntu输入su提示认证失败的解决方法
用su切换,输入密码提示认证失败,这下搞了吧,后来一经查阅原来Ubuntu安装后,root用户默认是被锁定了的,不允许登录,也不允许 su 到 root ,对于桌面用户来说这个可能是为了增强安全性,但 ...
- linux下安装redis3.2
这部分来自网络: http://blog.csdn.net/cuibruce/article/details/53501532 1.下载 下载地址:http://www.redis.io/downlo ...