题目链接:

pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669

Problem Description
The Sky is Sprite.

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.
 
Input
The input contains multiple test cases.

Each case two nonnegative integer a,b (0<a, b<=2^31)
 
Output
output 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. 
 
Sample Input
77 51
10 44
34 79
 
Sample Output
2 -3
sorry
7 -3
 
Author
yifenfei
 
Source

PS:

扩展欧几里德模板题。

附:扩展欧几里德解说:http://blog.csdn.net/u012860063/article/details/39760003

代码例如以下:

#include <cstdio>
#include <cstring>
#include <cmath>
typedef __int64 LL; LL exgcd(LL a,LL b,LL &x,LL &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
LL r = exgcd(b,a%b,x,y);
LL t = x;
x = y;
y = t-a/b*y;
return r;
} int main()
{
LL a,b,x,y;
while(scanf("%I64d%I64d",&a,&b)!=EOF)
{
LL d = exgcd(a,b,x,y);
if(1%d)//不能整除
printf("sorry\n");
else
{
while(x<0)
x+=b,y-=a;
printf("%I64d %I64d\n",x,y);
}
}
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(扩展欧几里德, 数学题)

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

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

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

  4. hdu 2669 Romantic 扩展欧几里得

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

  5. HDU 2669 Romantic【扩展欧几里德】

    裸的扩展欧几里德,求最小的X,X=((X0%b)+b)%b,每个X都对应一个Y,代入原式求解可得 #include<stdio.h> #include<string.h> ty ...

  6. hdu 2669 Romantic

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

  7. HDU2669 Romantic 扩展欧几里德 对我来说有陷阱

    这道题对我来说有陷阱虽说是赤果果的扩展欧几里德,看样子基本攻还是不够哈,基本功夫一定要好,准备每天上那种洗脑课时分  多看看数论书,弥补一下 自己 狗一样的基础, 这道题用到了一个性质: 对于不定整数 ...

  8. hdu 2669 Romantic (乘法逆元)

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

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

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

随机推荐

  1. ajax动态刷新下拉框

    动态post,避免直接给页面传输大量数据 /** * ajax通过商品刷新供应商 * by_kangyx * @throws IOException */ @RequestMapping(params ...

  2. python 三——列表、字典、元祖、字符串、set

    本节内容 1.列表 2.元祖 3.字典 4.字符串 不可变类型:整型.字符串.元组tuple 可变类型:列表list.字典dict 1.列表 >>> names ['Alex', ' ...

  3. Java列出接口实现的所有接口

    package com.tj; public class MyClass2 { public static void main(String[] args) { Class cls = java.ut ...

  4. Installing pip on CentOS 7 for Python

    nstalling pip on CentOS 7 for Python 2.x On CentOS 7, you have to install setup tools first, and the ...

  5. numpy.clip(a, a_min, a_max, out=None)(values < a_min are replaced with a_min, and those > a_max with a_max.)

    numpy.clip(a, a_min, a_max, out=None) Clip (limit) the values in an array. Given an interval, values ...

  6. caffe+vs2013+window10+GPU(CPU)配置

    参考:http://www.echojb.com/cuda/2017/03/15/350138.html https://www.zhihu.com/question/56111727 第一步:首先确 ...

  7. 树形DP专题

    DP是我的弱项, 此专题意在总结树形DP的解题思路. 最小代价遍历一棵树 给定一棵带边权的树 $T=(V,E)$ , 遍历它 (树的每个节点都访问至少一次) 所需的最小代价. 这里的代价由具体问题所定 ...

  8. POJ 2396 Budget ——有上下界的网络流

    给定矩阵的每行每列的和,和一些大于小于等于的限制.然后需要求出一组可行解. 上下界网络流. 大概的思想就是计算出每一个点他需要强行流入或者流出的量,然后建出超级源点和汇点,然后删除下界,就可以判断是否 ...

  9. 【2018.10.15】WZJ笔记(数论)

    1. 证明:对于任意质数$p\gt 3$,$p^2-1$能被$24$整除. 证:平方差公式,$p^2-1 = (p-1)(p+1)$. 再把$24$分解质因数$2^3*3$. 三个相邻的自然数中至少有 ...

  10. mode(BZOJ 2456)

    Description 给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数. Input 第1行一个正整数n.第2行n个正整数用空格隔开. Output 一行一个正整数表 ...