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发现似乎不可 ...
 
随机推荐
- python爬虫之requests模块
			
一. 登录事例 a. 查找汽车之家新闻 标题 链接 图片写入本地 import requests from bs4 import BeautifulSoup import uuid response ...
 - @Transactional的readOnly、timeout
			
1.@Transactional的readOnly 在使用@Transactional注解的时候,有一个属性是readOnly,默认值是false readOnly的意思就是当前的方法是只读的,也就是 ...
 - vim 插件 for gbasic
			
https://github.com/tracyone/vim-gbasic 功能特点 提供正确语法显示,包括关键字,bulidin函数,注释,强调注释,TODO注释 提供正确的折叠; 准确secti ...
 - JSON数组字典解析
			
遇到这样的字典数组字符串 priceRange = "[{\"id\":149075584861800,\"price\":9.9,\"nu ...
 - L165
			
New evidence of how the Norse became long-distance marinersAccording to the saga of Erik the Red, “s ...
 - jquery过滤特殊字符及js字符串转为数字
			
//替换特殊字符 $(this).val($(this).val().replace(/[~'!<>@#$%^&*()-+_=:]/g, "")); 方法主要有 ...
 - vue.js 源代码学习笔记  ----- 工具方法 perf
			
import { inBrowser } from './env' export let mark export let measure if (process.env.NODE_ENV !== 'p ...
 - HashSet实现原理及源码分析
			
HashSet简介 HashSet是Set接口实现,它按照Hash算法来存储集合中的元素 不保证元素顺序 HashSet是非同步的,如果多个线程同时访问一个HashSet,要通过代码来保证其同步 集合 ...
 - [置顶]
        flume高并发优化——(15)中间件版本升级
			
在系统平稳运行一年的基础上,为提供更好的服务,现针对java,kafka,flume,zk,统一进行版本升级,请各位小伙伴跟着走起来,不要掉队啊! 名称 老版本号 新版本号 jdk 1.7.0_25 ...
 - Java调用本地方法又是怎么一回事
			
JNI JNI即Java Native Interface,它能在Java层实现对本地方法的调用,一般本地的实现语言主要是C/C++,其实从虚拟机层面来看JNI挺好理解,JVM主要使用C/C++ 和少 ...