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. $python用装饰器实现一个计时器

    直接上代码: import time from functools import wraps # 定义装饰器 def fn_timer(function): @wraps(function) def ...

  2. ABP官方文档翻译 1.2 N层架构

    N层架构 介绍 ABP架构 其他(通用) 领域层 应用层 基础设施层 网络和展现层 其他 总结 介绍 应用程序代码库的分层架构是被广泛认可的可以减少程序复杂度.提高代码复用率的技术.为了实现分层架构, ...

  3. C++ 第三十三天

    Ⅰ.类成员函数的隐式参数 T *const this . 就是说对于某个类的成员函数 returnType function() 的真实面目其实是这样的 returnType function(T * ...

  4. sqlx基础语法与应用

    基础: ``` 引用:_ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" ``` 初始化 ...

  5. 20145310 《Java程序设计》第4周学习总结

    20145310 <Java程序设计>第4周学习总结 教材学习内容总结 本周主要进行第五章和第六章的学习. 第六章 继承与多态 子类(Inherit)继承父类,避免重复的行为定义,不过并非 ...

  6. 20145335郝昊《java程序设计》第5周学习总结

    20145335郝昊<Java程序设计>第5周学习总结 教材学习内容总结 第八章 语法与继承架构 使用try.catch 特点: - 使用try.catch语法,JVM会尝试执行try区块 ...

  7. 异常: error MSB8008: 指定的平台工具集(V120)未安装或无效

    打开项目属性->配置属性->常规,平台工作集,选为v100

  8. Ubuntu 下安装Beyond Compare【转】

    本文转载自:https://blog.csdn.net/bingyu9875/article/details/52856675 官网下载安装包:http://www.scootersoftware.c ...

  9. 配置Gitlab Push自动触发jenkins构建

    一. 下载gitlab plugin Jenkins>插件管理 下载并安装gitlab plugin 二. 配置gitlab认证 路径Jenkins>Credentials>Syst ...

  10. Interleaving String,交叉字符串,动态规划

    问题描述: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Give ...