HDU 2669
题目大意:
已知线性方程ax+by=1; 输入a, b的值, 要求输出整数解x, y的值(输出x, y的最小整数解), 若没有解, 输出"sorry".
#include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010 LL extend_gcd(LL a, LL b, LL &x, LL &y)
{
if(b == )
{
x = ;
y = ;
return a;
}
else
{
LL r = extend_gcd(b, a%b, y, x);
y -= x*(a/b);
return r;
}
} int main()
{
int a, b;
while(scanf("%d%d", &a, &b)==)
{
LL t, p;
LL ans = extend_gcd(a, b, t, p);
if(%ans)
printf("sorry\n");
else
{
LL x = *t/ans; //特解
x = (x%(b/ans)+(b/ans))%(b/ans); //最小整数解
LL y = (-a*x)/b;
printf("%lld %lld\n", x, y);
}
} return ;
}
HDU 2669的更多相关文章
- hdu 2669 Romantic
Romantic Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 2669 Romantic(扩展欧几里德)
题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...
- hdu 2669 Romantic (乘法逆元)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2669 第六周 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the ...
- 【HDU 2669】Romantic
Problem Description The Sky is Sprite.The Birds is Fly in the Sky.The Wind is Wonderful.Blew Throw t ...
- 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(裸的拓展欧几里得)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 2669(扩展欧几里得)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
随机推荐
- IOS7 edgesForExtendedLayout
在iOS 7中,苹果引入了一个新的属性,叫做[UIViewController setEdgesForExtendedLayout:],它的默认值为UIRectEdgeAll.当你的容器是naviga ...
- 需求:输入一个年份和月份 ,显示当前月日情况 ,星期数要对应准确 * 1.1900年1月1号开始 * 2.星期 : 直接用总天数对7求余数 31 28 59 / 7 = 5 * 3.以\t来个开
public class Demo4 { /** * @param args */ public static void main(String[] args) { // TODO Auto-gene ...
- 第三方的图片加载( Android-Universal-Image-Loader)
Android-Universal-Image-Loader是一个开源的UI组件程序,该项目的目的是提供一个可重复使用的仪器为异步图像加载,缓存和显示. (1).使用多线程加载图片(2).灵活配置Im ...
- WebUpLoder 能自动预览,能多实例,包括后台demo
样式在网上找的.样子: 懒得写别的了,代码里面我写的注释挺详细的:https://github.com/zhangsai521314/WebUpLoder 写文不易,转载请注明出处:http://ww ...
- (转)pymysql 连接mysql数据库---不支持中文解决
往数据库里插入中文时出现异常:UnicodeEncodeError: 'latin-1' codec can't encode characters 就是编码的问题,pymysql默认的编码是lati ...
- IT关键词,发现与更新,点成线,线成面,面成体
时序图 1.什么是时序图 2.如何看懂时序图 3.时序图的作用 4.如何绘制时序图 分布式 一个业务分拆多个子业务,部署在不同的服务器上. 分布式是指将不同的业务分布在不同的地方. 而集群指的是将几台 ...
- (十七)linux网络命令 vconfig ifconfig
增删VLAN vconfig add eth0 10 vconfig rem eth0.10重启网卡 ifconfig eth0.101 up ifconfig eth0.10 ...
- maven工程使用spring-boot-devtools进行热部署,更改代码避免重启web容器
spring-boot-devtools 是一个为开发者服务的一个模块,其中最重要的功能就是自动应用代码更改到最新的App上面去.相关Blog: 点击打开链接 原理是在发现代码有更改之后,重新启动应用 ...
- MySQL查询分析器EXPLAIN或DESC
转载:http://chenzehe.iteye.com/blog/1682081 MySQL可以通过EXPLAIN或DESC来查看并分析SQL语句的执行情况,如下需要计算2006年所有公司的销售额, ...
- java:同步和死锁
多个线程共享一个资源的时候需要进行同步(否则会出现错误:如负数,重复数),但是过多的同步会造成死锁. synchronized(this) { } 非同步情况: public class SyncTh ...