题目大意:

  已知线性方程ax+by=1; 输入a, b的值, 要求输出整数解x, y的值(输出x, y的最小整数解), 若没有解, 输出"sorry".

 
分析:
  求线性方程的解用扩展欧几里得算法,令gcd(a,b)=d, 如果1是d的倍数表示方程有解, 否则无解.
 
 
 
 
 
代码如下:
 
 
 
 
 #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的更多相关文章

  1. hdu 2669 Romantic

    Romantic Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  2. HDU 2669 Romantic(扩展欧几里德)

    题目链接:pid=2669">http://acm.hdu.edu.cn/showproblem.php?pid=2669 Problem Description The Sky is ...

  3. hdu 2669 Romantic (乘法逆元)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. HDU 2669 第六周 I题

    Description The Sky is Sprite.  The Birds is Fly in the Sky.  The Wind is Wonderful.  Blew Throw the ...

  5. 【HDU 2669】Romantic

    Problem Description The Sky is Sprite.The Birds is Fly in the Sky.The Wind is Wonderful.Blew Throw t ...

  6. HDU 2669 Romantic 扩展欧几里德---->解不定方程

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. HDU 2669 Romantic (扩展欧几里得定理)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  8. HDU 2669 Romantic(裸的拓展欧几里得)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. hdu 2669(扩展欧几里得)

    Romantic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

随机推荐

  1. Linux C++线程池

    .为什么需要线程池? 部分应用程序需要执行很多细小的任务,对于每个任务都创建一个线程来完成,任务完成后销毁线程,而这就会产生一个问题:当执行的任务所需要的时间T1小于等于创建线程时间T2和销毁线程时间 ...

  2. JavaScript中的数组遍历forEach()与map()方法以及兼容写法

    原理: 高级浏览器支持forEach方法 语法:forEach和map都支持2个参数:一个是回调函数(item,index,list)和上下文: forEach:用来遍历数组中的每一项:这个方法执行是 ...

  3. [转] charles使用教程指南

    charles使用教程指南   0x01 前言: Charles是一款抓包修改工具,相比起burp,charles具有界面简单直观,易于上手,数据请求控制容易,修改简单,抓取数据的开始暂停方便等等优势 ...

  4. KEGG数据库

    参考:KEGG数据库中文教程 - 博奥  &[学习笔记]KEGG数据库 - 微信 学习一个技能最主要的事情你必须知道,那就是能通过它来做什么? KEGG数据库里面有什么? 如何查询某一特定的代 ...

  5. css学习记录

    1 !important 表示此属性需要优先考虑: <head>    <title>Page Title</title>    <style type=&q ...

  6. 与String有关的强制转换

    String --> int int i = Integer.parseInteger("123"); String --> double double d = Dou ...

  7. MySQL DDL 整理

    DDL is Data Definition Language statements. Some examples:数据定义语言,用于定义和管理 SQL 数据库中的所有对象的语言 -- 清空表内容 T ...

  8. mongo 相关命令

    mongo导入数据: 1. 先进入找到mongo 安装目录 执行 ./mongo 进入mongo 2. mongorestore -u 用户名 -p 密码 -d 数据库 —drop 文件存在路径 显示 ...

  9. python——django使用mysql数据库(二)

    上一篇中,我们已经讲述了如何初始化一个django数据库,这一章就来讲讲在实际的项目中如何使用我们初始化的数据库呢? 如还未进行初始化数据库操作,请参考python——django使用mysql数据库 ...

  10. WPF进度条系列②旋转小圆圈

     写在之前: 关于WPF的样式,我也是学习了很多朋友的文章才有了下面的东西,因为时间有些久远 & 备份的链接也都不在了. 所以,究竟是看过哪些文章,也是记不清楚了…… 请见谅. ------- ...