Romantic

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6643    Accepted Submission(s): 2772

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
 
注意:求 a*x+b*y=1 中的x和y,给定a和b。
     (答案中的x不能是负数)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std; #define ll long long
ll n,m; ll ex_gcd(ll a,ll b,ll &x,ll &y)
{
if (b==)
{
x=; y=;
return a;
}
ll r=ex_gcd(b,a%b,y,x);
y-=a/b*x;
return r;
}
/*
ll ex_gcd(ll a,ll b,ll &x,ll &y)
{
if(!b)
{
x=1,y=0;
return a;
}
ll d=ex_gcd(b,a%b,x,y);
ll x1=x;
x=y;
y=x1-(a/b)*y;
return d;
}*/ //这段也是可以的
int main()
{
while(~scanf("%lld%lld",&n,&m))
{
ll x,y;
ll gcd=ex_gcd(n,m,x,y);
if (gcd!=){ printf("sorry\n"); continue;}
else
{
while(x<) x+=m;
y=(-n*x)/m;
printf("%lld %lld\n",x,y);
} } return ;
}

HDU 2669 Romantic (扩展欧几里得定理)的更多相关文章

  1. hdu 2669 Romantic 扩展欧几里得

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

  2. hdu2669-Romantic-(扩展欧几里得定理)

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

  3. poj1061-青蛙的约会-(贝祖定理+扩展欧几里得定理+同余定理)

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:132162   Accepted: 29199 Descripti ...

  4. poj 1061(扩展欧几里得定理求不定方程)

    两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特 ...

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

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

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

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

  7. hdu 5512 Pagodas 扩展欧几里得推导+GCD

    题目链接 题意:开始有a,b两点,之后可以按照a-b,a+b的方法生成[1,n]中没有的点,Yuwgna 为先手, Iaka后手.最后不能再生成点的一方输: (1 <= n <= 2000 ...

  8. hdu_2669 Romantic(扩展欧几里得)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2669 Romantic Time Limit: 2000/1000 MS (Java/Others)  ...

  9. HDU A/B 扩展欧几里得

    Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1).   Input 数据的 ...

随机推荐

  1. git 常用的撤销操作

    git 开发时的使用流程,从同事那里学习的, 第一步,先建立一个新的分支,可以在GITLAB或通过命令git checkout -b newbranch 或通过IDE插件 第二步,让项目切换到该分支, ...

  2. tensorflowxun训练自己的数据集之从tfrecords读取数据

    当训练数据量较小时,采用直接读取文件的方式,当训练数据量非常大时,直接读取文件的方式太耗内存,这时应采用高效的读取方法,读取tfrecords文件,这其实是一种二进制文件.tensorflow为其内置 ...

  3. ARKit 研究笔记一

    软件需求:Xcode9.x .blender 硬件需求:iphone 6s + 系统:iOS 11 + 技能储备: ARKit .SceneKit(苹果提供的3d游戏库) 或 SpriteKit(苹果 ...

  4. Linux远程管理器xshell和xftp使用教程,以及遇到关闭Xshell后项目也停止的解决方法

    1.xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议. 2.是一个基于 MS windows 平台的功能强大的 ...

  5. Datatable To List<Entity>

    public static DataTable ToDataTable<T>(this IEnumerable<T> varlist) { DataTable dtReturn ...

  6. 关于Log4Net的使用和配置

    1. 添加log4net.dll引用 2.在添加引用的那层的 AssemblyInfo.cs         注册   : [assembly: log4net.Config.XmlConfigura ...

  7. windows server 2012泛域名解析配置

    应测试要求,要将一个泛域名(*.office.baibai.com)解析到一个内网的IP(10.1.100.240)地址上(使用域控DNS解析)...以下为我的配置过程,做的时候将图顺便接了下来: 1 ...

  8. 20145307第十周JAVA学习报告

    教材学习内容总结 Java的网络编程 1.计算机网络概述 (1)路由器和交换机组成了核心的计算机网络,计算机只是这个网络上的节点以及控制等,通过光纤.网线等连接将设备连接起来,从而形成了一张巨大的计算 ...

  9. 20145328 《Java程序设计》实验五实验报告

    20145328 <Java程序设计>实验五实验报告 实验名称 Java网络编程 实验内容 用书上的TCP代码,实现服务器与客户端. 客户端与服务器连接 客户端中输入明文,利用DES算法加 ...

  10. 试编hello world

    这里是一些vim的使用方法: 这时不知道怎么编译了  看了上面的知识 也问了志伟,我就知道了.是要“./hello”就可以了 自己敲了代码,今后也会多试运行,编译,得尽快安装虚拟机了.