【题目链接】

点击打开链接

【算法】

列出同余方程,然后用exgcd求解

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; typedef long long LL; LL p,q,x,y,n,m,L,r; template <typename T> void read(T &x) {
LL f=; char c = getchar(); x=;
for (; !isdigit(c); c = getchar()) { if (c=='-') f=-; }
for (; isdigit(c); c = getchar()) x=x*+c-'';
x*=f;
} inline LL exgcd(LL a,LL b,LL &x,LL &y) {
LL r;
if (b == ) {
x = ;
y = ;
return a;
}else {
r = exgcd(b,a%b,y,x);
y -= a / b * x;
return r;
}
} int main() { read(x); read(y); read(m); read(n); read(L); r = exgcd(L,n-m,p,q); if ((x - y) % r) puts("Impossible");
else cout<< (((q * (x - y) / r) % L) + L) % L << endl; return ; }

【POJ 1061】 青蛙的约会的更多相关文章

  1. poj 1061 青蛙的约会 拓展欧几里得模板

    // poj 1061 青蛙的约会 拓展欧几里得模板 // 注意进行exgcd时,保证a,b是正数,最后的答案如果是负数,要加上一个膜 #include <cstdio> #include ...

  2. ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德

    POJ 1061 青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu  Descr ...

  3. POJ.1061 青蛙的约会 (拓展欧几里得)

    POJ.1061 青蛙的约会 (拓展欧几里得) 题意分析 我们设两只小青蛙每只都跳了X次,由于他们相遇,可以得出他们同余,则有: 代码总览 #include <iostream> #inc ...

  4. poj 1061 青蛙的约会 (扩展欧几里得模板)

    青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status ...

  5. POJ 1061青蛙的约会(拓展欧几里德算法)

    题目链接: 传送门 青蛙的约会 Time Limit: 1000MS     Memory Limit: 65536K Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见 ...

  6. POJ 1061 青蛙的约会

                            青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 82859   A ...

  7. poj 1061青蛙的约会

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 90083   Accepted: 16257 Descripti ...

  8. POJ 1061 青蛙的约会 扩展欧几里德--解不定方程

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 81606   Accepted: 14116 Descripti ...

  9. POJ 1061 青蛙的约会(拓展欧几里得求同余方程,解ax+by=c)

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 122871   Accepted: 26147 Descript ...

  10. poj 1061 青蛙的约会 扩展欧几里德

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K       Description 两 只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们 ...

随机推荐

  1. Highcharts 动态制作3D柱状图

    学习参考菜鸟网站:http://www.runoob.com/highcharts/highcharts-tutorial.html 我是通过后端返回设备数据,进行前端出图,效果如下: 代码如下: d ...

  2. HDU 5667 Sequence【矩阵快速幂+费马小定理】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5667 题意: Lcomyn 是个很厉害的选手,除了喜欢写17kb+的代码题,偶尔还会写数学题.他找到 ...

  3. Unity3D 对象池思想 在游戏开发中的运用

    分类:U3D 1.在王者荣耀中,每30秒小兵会出现一波,出现之后会被敌方玩家或敌方小兵销毁,一局游戏下来,小兵会被创建多次,同时也会被销毁,在游戏中,这种频繁的创建和销毁游戏对象是很损耗性能的.在游戏 ...

  4. P1540 机器翻译(STL 链表)

    题目背景 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 题目描述 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于每个英文单词,软件会先 ...

  5. 《Java虚拟机原理图解》 1.2.3、Class文件中的常量池详解(下)

    CONSTANT_Fieldref_info, CONSTANT_Name_Type_info) 一般而言,我们在定义类的过程中会定义一些 field 字段,然后会在这个类的其他地方(如方法中)使用到 ...

  6. install Python 2.7 and Python 3.3 on CentOS 6

    来自:http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/ In this guide I will show you ...

  7. Go -- 一致性哈希算法

    一致性哈希算法在1997年由麻省理工学院的Karger等人在解决分布式Cache中提出的,设计目标是为了解决因特网中的热点(Hot spot)问题,初衷和CARP十分类似.一致性哈希修正了CARP使用 ...

  8. 五步掌握Git的基本开发使用命令

    第一步:设置全局变量: git config --global user.name "gang.li" git config --global user.email "l ...

  9. mmall 项目实战(一)项目初始化

    1.创建 数据库 及 表 数据脚本: /* Navicat Premium Data Transfer Source Server : 182.92.82.103 Source Server Type ...

  10. 【试水CAS-4.0.3】第06节_CAS服务端配置HTTPS

    完整版见https://jadyer.github.io/2012/05/30/tomcat-https/ /** * @see CAS服务端配置HTTPS * @see -------------- ...