Romantic

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

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
 
题解:由ax+by = gcd(a,b) 当 a,b互素是才会有解。然后X要是尽量小的正数,假设我们得到的是 X0 ,在有解的情况下方程ax+by=c的通解为 {X0*(c/d)+k*b/gcd(a,b)} (k = ..-2,-1,0,1,2..)
所以我们可以得到在最小的X为 (X0%b+b)%b.代入得Y
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL; LL extend_gcd(LL a,LL b,LL &x,LL &y){
if(!b){
x=,y = ;
return a;
}else{
LL x1,y1;
LL d = extend_gcd(b,a%b,x1,y1);
x = y1;
y = x1 - a/b*y1;
return d;
}
}
int main()
{
LL a,b,x,y;
while(~scanf("%lld%lld",&a,&b)){
LL d = extend_gcd(a,b,x,y);
if(d!=){
printf("sorry\n");
}else{
x = (x%b+b)%b;
y = (-a*x)/b;
printf("%lld %lld\n",x,y);
}
}
return ;
}

hdu 2669(扩展欧几里得)的更多相关文章

  1. hdu 2669 扩展欧几里得(裸)

    #include<stdio.h> #include<iostream> #define ll __int64 ll gcd(ll a,ll b,ll &x,ll &a ...

  2. HDU 5114 扩展欧几里得

    题目大意:给你两个球的坐标 他们都往(1, 1)这个方向以相同的速度走,问你他们在哪个位置碰撞. 思路:这种题目需要把x方向和y方向分开来算周期,两个不同周期需要用扩展欧几里得来求第一次相遇. #in ...

  3. HDU 4180 扩展欧几里得

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

  4. HDU RSA 扩展欧几里得

    Problem Description RSA is one of the most powerful methods to encrypt data. The RSA algorithm is de ...

  5. 扩展欧几里得 hdu 1576

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 不知道扩展欧几里得的同学可以参考:https://blog.csdn.net/zhjchengf ...

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

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

  7. hdu 1573 A/B (扩展欧几里得)

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

  8. hdu 1576 A/B 【扩展欧几里得】【逆元】

    <题目链接> <转载于 >>> > A/B Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)( ...

  9. [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)

    Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...

随机推荐

  1. 19.VUE学习之- v-for与computed结合功能 筛选实例讲解

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 数据结构-单链表(Linked List)

    #include <stdio.h> #include <stdlib.h> #define LIST_INIT_SIZE 10 #define LISTINCREMENT 1 ...

  3. GBK UTF8 GB2132

    GBK就是在保存你的帖子的时候,一个汉字占用两个字节,外国人看会出现乱码,为此我中华为自己汉字编码而形成之解决方案. UTF8就是在保存你的帖子的时候,一个汉字占用3个字节.但是外国人看的话不会乱码. ...

  4. C语言中可变参数的使用

    在C语言程序编写中我们使用最多的函数一定包括printf以及很多类似的变形体.这个函数包含在C库函数中,定义为 int printf( const char* format, ...); 除了一个格式 ...

  5. 《鸟哥的Linux私房菜》学习笔记(0)——磁盘与文件系统管理

    一.Linux的登陆流程 login: 用户名:每个用户名都有一个用户ID(用户标识符),计算机处理的就是用户ID(数字)而不是用户名(字符),. 认证机制:Authentication,比如密码或者 ...

  6. Redis数据结构以及Strings型操作

    Redis数据结构图: Strings型   <String key,String value>: keys * 查看所有key get 获取key的value值 append 向key对 ...

  7. 48、android代码架构总结

    之前是按功能模块进行分类,现在随着功能模块越来越多,代码层次不再清晰,所以修改了工程结构: 之前: 经过修改现在: 1.更严谨的遵循mvc架构 bean目录存放的是数据模型 ui存储的是activit ...

  8. IOS开发学习笔记017-第一个IOS应用

    第一个IOS应用程序,就从最简单的开始吧. 1.先了解一下开发环境,Xcode的相关组成 2.还有模拟器 3.运行与停止按钮 4.新建一个工程 5.看看main函数里都有啥 6.现在来添加一个控件 1 ...

  9. Python-S9——Day110-Git继续

    1 当日内容概要 2 内容回顾 3 Git版本控制之多人协同开发 4 Git版本控制之fork 5 版本控制之其他 6 Redis之字典基本操作 7 Django中操作Redis 8 Django缓存 ...

  10. sql2005 和sql2008 同时安装

    Hkey_local_machine\Software\Wow6432Node\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM 中的ShellSEM重 ...