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

题意:求解方程 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. Linux-workqueue讲解

    =============  参考  ============= 代码:linux-3.10.65/kernel/workqueue.c =============================== ...

  2. HDU 1021 Fibonacci Again( 同余水 )

    链接:传送门 题意:现在给出 Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).问第 n 项能不能整除 ...

  3. 训练1-H

    小明今年3岁了, 现在他已经能够认识100以内的非负整数, 并且能够进行100以内的非负整数的加法计算. 对于大于等于100的整数, 小明仅保留该数的最后两位进行计算, 如果计算结果大于等于100, ...

  4. 【模板】 最大流模板(ISAP)

    题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来M行每行 ...

  5. rtsp://admin:12345@192.168.1.198/mpeg4/main/ch01/av_stream

    rtsp://admin:12345@192.168.1.198/mpeg4/main/ch01/av_stream

  6. ASP.NET中的Webconfig 和 Global.asax区别

    Web.Config与Global.asax的区别: Config可以根据不同的错误类型定义不同的错误页,网站重定义转向新的错误页面. Global,在全局错误中写入应用程序事件错误信息,并在当前页输 ...

  7. [jQuery]文本框text变化事件

    $("#key").live("keyup",function(){   })

  8. [Web Worker] Introduce to Web Worker

    What is web worker for? OK, read it docs to get full details idea. Or just a quick intro to web work ...

  9. 防止 Chrome 屏蔽 非官方 扩展程序 教程(二)

    说明 前面介绍过一篇通过开发人员模式载入扩展程序的方法,尽管能够正常使用,可是每次又一次打开 Chrome 都会弹出询问窗体,比較麻烦.这里介绍第二种防止屏蔽的方法.与前一种方法相比,尽管应用的步骤多 ...

  10. DNS查询报文实例

    2.2 DNS查询报文实例 以www.baidu.com为例,用Wireshark俘获分组,结合2.1的理论内容,很容易看明白的,DNS请求报文如下: 图7 DNS请求报文示例 2.3 DNS回答报文 ...