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. mycat实战之性能测试

    1.安装性能监控工具 1.1 nmon 安装nmon de >#下载地址 http://nmon.sourceforge.net/pmwiki.php?n=Site.Download nmon1 ...

  2. Java 对比Hashtable、Hashmap、Treemap有什么不同?

    ①基本理解 Hashtable.Hashmap.Treemap都是最常见的一些Map实现,是以键值对的形式存储和操作数据的容器类型. Hashtable是Java类库提供的一个哈希实现,本身是同步的, ...

  3. Linux学习笔记之阿里云ECS部署LAMP环境

    LAMP指Linux+Apache+MySQL/MariaDB+Perl/PHP/Python,是一组常用来搭建动态网站或者服务器的开源软件.它们本身都是各自独立的程序,但是因为常被放在一起使用,拥有 ...

  4. [HNOI2019]校园旅行(构造+生成树+动规)

    题目 [HNOI2019]校园旅行 做法 最朴素的做法就是点对扩展\(O(m^2)\) 发现\(n\)比较小,我们是否能从\(n\)下手减少边数呢?是肯定的 单独看一个颜色的联通块,如果是二分图,我们 ...

  5. Spring提前加载与懒加载

    首先,Spring默认是提前加载,这意味着当项目启动,spring初始化,spring会把所有的扫描包下的 ,所有带spring 注解(@Component.@Repository.@Service. ...

  6. java语言基本环境搭建

    从放假开始,就开始路陆陆续续了解关于java语言的学习.首先从语言编辑环境就和以前学习的c语言会有些不同,对java语言的学习也有了很大很多新的认识. 首先从官网上下载jdk,按照娄老师给我们的操作提 ...

  7. yarn命令使用

    yarn 常用命令 修改日期 2017.12.26 最初接触 yarn 还是在 0.17.10 版本,由于各种各样的原因,使用时没 npm 顺手, 目前 yarn 的版本已经升级为 1.3.2 各种之 ...

  8. C# 操作FTP

    操作FTP管理类: using System; using System.Collections.Generic; using System.Text; using System.Net; using ...

  9. Row_Number() over( PARTITION By cno ...)

    转自:https://blog.csdn.net/qq_25237107/article/details/644429691.在 MSSQL,oracle 有partition by 的用法creat ...

  10. R中去除为NA的行--转载

    下面用实例来说明这两个函数的作用: 这是一个数据框final: gene hsap mmul mmus rnor cfam 1 ENSG00000208234 0 NA NA NA NA 2 ENSG ...