HDU 2669 Romantic(裸的拓展欧几里得)
Romantic
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8536 Accepted Submission(s):
3638
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.
Each case
two nonnegative integer a,b (0<a, b<=2^31)
are more answers than the X smaller one will be choosed. If no answer put
"sorry" instead.
10 44
34 79
sorry
7 -3
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <algorithm> #define INF 0x7fffffff
#define EPS 1e-12
#define MOD 1000000007
#define PI 3.141592653579798
#define N 100000 using namespace std; typedef long long ll; ll e_gcd(ll a, ll b, ll &x, ll &y)
{
ll d = a;
if (b != )
{
d = e_gcd(b, a%b, y, x);
y -= a / b * x;
}
else
{
x = ; y = ;
}
return d;
} ll cal(ll a, ll b, ll c)
{
ll x, y;
ll gcd = e_gcd(a, b, x, y);
if (c%gcd != ) return -;
x *= c / gcd;
y *= c / gcd;
if (b < ) b = -b;
ll ans = x % b;//最小的x,因为ax+by=c,尽量把ax分给b,多些y,少些x
if (ans <= ) ans += b;
return ans;
} int main()
{
ll a, b;
while (cin>>a>>b)
{
ll ans = cal(a, b, );
if (ans == -) printf("sorry\n");
else printf("%I64d %I64d\n", ans, ( - ans * a) / b);
}
return ;
}
HDU 2669 Romantic(裸的拓展欧几里得)的更多相关文章
- hdu 1576 A/B(拓展欧几里得)
A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2669 Romantic(扩展欧几里德, 数学题)
题目 //第一眼看题目觉得好熟悉,但是还是没想起来//洪湖来写不出来去看了解题报告,发现是裸的 扩展欧几里得 - - /* //扩展欧几里得算法(求 ax+by=gcd )//返回d=gcd(a,b) ...
- NOIP2012拓展欧几里得
拉板题,,,不说话 我之前是不是说过数据结构很烦,,,我想收回,,,今天开始的数论还要恶心,一早上听得头都晕了 先来一发欧几里得拓展裸 #include <cstdio> void gcd ...
- poj 1061 青蛙的约会 拓展欧几里得模板
// poj 1061 青蛙的约会 拓展欧几里得模板 // 注意进行exgcd时,保证a,b是正数,最后的答案如果是负数,要加上一个膜 #include <cstdio> #include ...
- bzoj4517: [Sdoi2016]排列计数--数学+拓展欧几里得
这道题是数学题,由题目可知,m个稳定数的取法是Cnm 然后剩下n-m本书,由于编号为i的书不能放在i位置,因此其方法数应由错排公式决定,即D(n-m) 错排公式:D[i]=(i-1)*(D[i-1]+ ...
- POJ 2891 Strange Way to Express Integers(拓展欧几里得)
Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express ...
- POJ1061 青蛙的约会-拓展欧几里得
Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事 ...
- BZOJ-2242 计算器 快速幂+拓展欧几里得+BSGS(数论三合一)
污污污污 2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 2312 Solved: 917 [Submit][S ...
- BZOJ-1407 Savage 枚举+拓展欧几里得(+中国剩余定理??)
zky学长实力ACM赛制测试,和 大新闻(YveH) 和 华莱士(hjxcpg) 组队...2h 10T,开始 分工我搞A,大新闻B,华莱士C,于是开搞: 然而第一题巨鬼畜,想了40min发现似乎不可 ...
随机推荐
- session、cookie、viewstate
session的用法 定义:保存在服务器内存的数据,sesson 只应该应用在需要跨页面且与每个访问用户相关的变量和对象存储上,session在默认情况下20分钟就过期,在页面之中最好不要过多使用,因 ...
- etl工具-Bireme
前段时间做数据仓库项目,自己实现了一部分etl功能,后面一直没有时间去深入挖掘.这个工具貌似不错,写个帖子做下记录: https://hashdatainc.github.io/bireme/READ ...
- .net的.aspx页面调试方法
做.net网站开发,有时候需要调试和察看变量, 1.设置好断点以后, 2.设置调试:VS 菜单: 调试————〉附加到进程————〉在 “可用进程” 列表中选择 标题为 "ASP.NET D ...
- MySQL之联合索引
以 index(a, b, c) 为例: 语句 发挥作用的索引 记忆方法(以三块板子过河记忆, 顺序很重要) WHERE a=3 只用到了a列 只走了a板子 WHERE a=3 AND b=5 使用了 ...
- Android程序员学WEB前端(7)-CSS(2)-伪类字体文本背景边框-Sublime
转载请注明出处:http://blog.csdn.net/iwanghang/article/details/76618373 觉得博文有用,请点赞,请评论,请关注,谢谢!~ 伪类: <!DOC ...
- Vue之通过代理设置跨域访问
我们使用脚手架创建的项目,可以在config项目中看到
- 基本SQL命令
1.SQL命令的使用规则 1.每条命令必须以 ; 结尾 2.SQL命令不区分字母大小写 3.使用 \c 来终止当前命令的执行 2.库的管理 1.库的基本操作 1.查看已有库 show database ...
- python对文件的读写
文件 File 什么是文件 文件是用于数据存储和单位 文件通常用来长期存储数据 文件中的数据是以字节为单位进行顺序存储的 文件的操作流程: 1. 打开文件 2. 读/写文件 3. 关闭文件 注: 任何 ...
- HDU3394Railway Tarjan连通算法
There are some locations in a park, and some of them are connected by roads. The park manger needs t ...
- linux自学(五)之开始centos学习,Xshell远程连接
上一篇:linux自学(四)之开始centos学习,网络配置 前面操作都是在电脑中的虚拟机上操作的,比较麻烦,需要来回切换.下面我将使用远程连接工具Xshell进行操作,Xshell直接百度下载即可. ...