**链接:****传送门 **

题意:求解方程 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( 拓欧水 )的更多相关文章

  1. HDU 2669 Romantic (扩展欧几里得定理)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  2. hdu 2669 Romantic 扩展欧几里得

    Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisf ...

  3. hdu 2669 Romantic

    Romantic Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  4. HDU 2669 Romantic(裸的拓展欧几里得)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. Romantic HDU - 2669(扩欧)

    #include<bits/stdc++.h> using namespace std; typedef long long LL; void gcd(LL a, LL b, LL &am ...

  6. HDU 2669 Romantic 扩展欧几里德---->解不定方程

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. hdu 2669 Romantic (乘法逆元)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  8. HDU 2669 Romantic(扩展欧几里德)

    题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...

  9. HDU 2669 Romantic(扩展欧几里德, 数学题)

    题目 //第一眼看题目觉得好熟悉,但是还是没想起来//洪湖来写不出来去看了解题报告,发现是裸的 扩展欧几里得 - - /* //扩展欧几里得算法(求 ax+by=gcd )//返回d=gcd(a,b) ...

随机推荐

  1. nyoj11-奇偶数分离

    奇偶数分离 时间限制:3000 ms  |  内存限制:65535 KB 难度:1 描述 有一个整型偶数n(2<= n <=10000),你要做的是:先把1到n中的所有奇数从小到大输出,再 ...

  2. MAVEN 构建包的引用

    1.什么叫构建包的引用? 当你存在两个maven项目分别是项目A,项目B时,且项目B要引用项目A的方法,那么你就用把项目A打成*.jar架包,放到本地的Maven仓库提供给项目B去引用. A.用命令到 ...

  3. Swagger在 NETcore 中的使用

    请参考 https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/getting-started-with-swashbuckle?view=asp ...

  4. ajax提交数据遇到400异常,原因及解决方案

    开发中遇到的问题, ajax的URL写的正确但是确无法正常跳转, 开发者模式下显示请求400异常. 前后台代码如下 ------------------------------------------ ...

  5. 多播 & multicast

    参考: http://blog.csdn.net/herbert5069/article/details/31358641

  6. 常用的Linux 命令

    来源于面试 求一条linux命令:查找当前目录下所有含有字符串type="json",文件名以.xml的所有文件 find . -name "*.xml"|xa ...

  7. 王立平--Object-c

    object-c通常写作objective-c或者obj-c,是依据C语言所衍生出来的语言.继承了C语言的特性,是扩充C的面向对象编程语言. 它主要使用于MacOSX和GNUstep这两个使用Open ...

  8. php面向对象之__isset和__unset

    php面向对象之__isset和__unset 一.简介 __isset和__unset都是对不可访问属性的操作,前者是检验的时候自动调用,后者是销毁的时候自动调用. 比如说在类外访问private的 ...

  9. elasticsearch如何安全重启节点

    elasticsearch如何安全重启节点 标签: elasticsearch 节点 | 发表时间:2016-05-24 03:58 | 作者:kfcman 分享到: 出处:http://www.it ...

  10. mysql如何查找表里的字段

    在开发项目的时候有个功能需要查看数据库中有哪些表,以及每个表有哪些字段,在网上查看了一下,现在分享给大家. Oracle: 查询数据表(Tables)名称:select Table_Name, Tab ...