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发现似乎不可 ...
随机推荐
- System.Zip
自XE2增加的System.Zip单元很好.注意事项: 1.文件压缩到文档后所使用的文件名会成为解压后的文件名,如果该文件名为指定文件名且无后缀名,那么解压出来的文件名也没有后缀名:
- C# POST请求 json格式
/* * url:POST请求地址,例如:url = "http://localhost:35229/ddn/GetPostData"; * postData:json格式的请求报 ...
- vue.js 源代码学习笔记 ----- 工具方法 option
/* @flow */ import Vue from '../instance/index' import config from '../config' import { warn } from ...
- CString与输入输出流对象问题。
在C++ 编程出现:cin>>Id;没有与这些操作匹配的">>"运算符: 你要看你的Id的数据类型,如果是CString等字符串,要用cin.getline ...
- (转)MapReduce Design Patterns(chapter 1)(一)
翻译的是这本书: Chapter 1.Design Patterns and MapReduce MapReduce 是一种运行于成百上千台机器上的处理数据的框架,目前被google,Hadoop等多 ...
- VMWare的共享文件的安装指南
引言:笔者这几天基于CentOS 7的精简版按照了一个虚拟机,悲催的是没有图形界面,但是非常需要共享文件的工作,在宿主机以及虚拟机之间实现文件共享,本文将描述如何实现此操作. VMWare菜单按照VM ...
- EasyPusher安卓直播推流到EasyDarwin开源流媒体服务器工程简析
EasyPusher主要有三部分组件组成:采集,编码,叠加,上传.在这个基础上同时支持本地存储\后台预览的功能.主要业务模块与相关类之间的关系如图所示: Created with Raphaël 2. ...
- 解决h5py的FutureWarning问题
h5py/__init__.py:: FutureWarning: Conversion of the second argument of issubdtype from `float` to `n ...
- Emgu cv 学习笔记
http://www.cnblogs.com/CoverCat/p/5003363.html emgu中imagebox与picturebox imagebox 是emgu 设置好厚,新出现的控件 ...
- HTML字符实体(Character Entities),转义字符串(Escape Sequence) 转
为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用.这些符号是不显示在我们最终看到的网页里的,那如果我们希 ...