HDU 2669 Romantic( 拓欧水 )
**链接:****传送门 **
题意:求解方程 X * a + Y * b = 1 的一组最小非负 X 的解,如果无解输出 "sorry"
思路:裸 exgcd
/*************************************************************************
> File Name: hdu2669.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月21日 星期日 18时34分40秒
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll exgcd(ll a,ll b,ll &x,ll &y){
if( b == 0 ){
x = 1 ; y = 0 ; return a;
}
ll d = exgcd( b , a%b , x , y );
ll tmp = x;
x = y; y = tmp - a/b*y;
return d;
}
int main(){
ll a , b , x , y;
while(~scanf("%lld%lld",&a,&b)){
ll d = exgcd( a , b , x , y);
ll c = 1;
if( c % d != 0 ) printf("sorry\n");
else{
x = x * (c/d);
x = ( x%(b/d) + b/d )%(b/d);
printf("%lld %lld\n",x,(1-a*x)/b);
}
}
return 0;
}
HDU 2669 Romantic( 拓欧水 )的更多相关文章
- HDU 2669 Romantic (扩展欧几里得定理)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 2669 Romantic 扩展欧几里得
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisf ...
- hdu 2669 Romantic
Romantic Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 2669 Romantic(裸的拓展欧几里得)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Romantic HDU - 2669(扩欧)
#include<bits/stdc++.h> using namespace std; typedef long long LL; void gcd(LL a, LL b, LL &am ...
- HDU 2669 Romantic 扩展欧几里德---->解不定方程
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 2669 Romantic (乘法逆元)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2669 Romantic(扩展欧几里德)
题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...
- HDU 2669 Romantic(扩展欧几里德, 数学题)
题目 //第一眼看题目觉得好熟悉,但是还是没想起来//洪湖来写不出来去看了解题报告,发现是裸的 扩展欧几里得 - - /* //扩展欧几里得算法(求 ax+by=gcd )//返回d=gcd(a,b) ...
随机推荐
- PHP 一句话木马
eval 函数 eval() 函数把字符串按照 PHP 代码来计算 该字符串必须是合法的 PHP 代码,且必须以分号结尾 如果没有在代码字符串中调用 return 语句,则返回 NULL.如果代码中存 ...
- php的优缺点(转)
1. 跨平台,性能优越,跟Linux/Unix结合别跟Windows结合性能强45%,并且和很多免费的平台结合非常省钱,比如LAMP(Linux /Apache/Mysql/PHP)或者FAMP(Fr ...
- Project Euler 50 Consecutive prime sum
题意: 素数41可以写成六个连续素数的和: 41 = 2 + 3 + 5 + 7 + 11 + 13 在小于一百的素数中,41能够被写成最多的连续素数的和. 在小于一千的素数中,953能够被写成最多的 ...
- 使用Flask_SQLAlchemy连接多个数据库
#!/usr/bin/env python #-*- coding: utf-8 -*- from flask import Flask from flask_sqlalchemy import SQ ...
- 做支付遇到的HttpClient大坑
前言 HTTPClient大家应该都很熟悉,一个很好的抓网页,刷投票或者刷浏览量的工具.但是还有一项非常重要的功能就是外部接口调用,比如说发起微信支付,支付宝退款接口调用等:最近我们在这个工具上栽了一 ...
- 【hihocoder 1303】模线性方程组
[题目链接]:http://hihocoder.com/problemset/problem/1303 [题意] [题解] /* x % m[1] = r[1] x % m[2] = r[2] x = ...
- DOM中元素节点,属性节点,文本节点的理解
节点信息 每个节点都拥有包含着关于节点某些信息的属性.这些属性是: nodeName(节点名称) nodeValue(节点值) nodeType(节点类型) nodeType nodeType 属性可 ...
- 洛谷—— P1120 小木棍 [数据加强版]
https://www.luogu.org/problem/show?pid=1120 题目描述 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50. 现在,他想把小木棍拼接 ...
- 使用Eclipse进行远程调控
什么是远程调试,就是在A机器上利用Eclipse单步跟踪调试B机器上的Web应用,当然调试A机器上Web应用也是没有问题的,90%我都是调试本机的Web应用,远程调试的意义我想我不用说了,大家都会想到 ...
- test environment bug
pxj::EsgServiceImpl.kmsProcess->Get:ESG JAR return data is:{"code":10000,"data&quo ...