【题目链接】

点击打开链接

【算法】

列出同余方程,然后用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. Centos7安装完成后一些基本操作

    1.基本操作一:主机名 # centos7有一个新的修改主机名的命令hostnamectl hostnamectl set-hostname --static www.node1.com # 有些命令 ...

  2. UVA 11346 Probability

    题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 3 10 5 20 1 1 1 2 2 0 输出样例#1: 23.348371% 0.000000% 100.00 ...

  3. java学习笔记总略

    二.正文(一)Java1.接口和抽象类的区别①抽象类里可以有构造方法,而接口内不能有构造方法.②抽象类中可以有普通成员变量,而接口中不能有普通成员变量.③抽象类中可以包含非抽象的普通方法,而接口中所有 ...

  4. Angular 路由⑦要素

    cnzt       http://www.cnblogs.com/zt-blog/p/7919185.html http://www.cnblogs.com/zt-blog/p/7919185.ht ...

  5. 管理weblogic服务的启动和停止

    2012-11-10 12:58 26036人阅读 评论(4) 收藏 举报 分类: WebLogic(10) 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 介绍 Weblog ...

  6. c++引用和const 用法 数组 指针

    非const引用,只能用object为其赋值: <c++primer>P52 而const引用则可以用临时变量为其赋值: 如: const int &r = 32://可以 int ...

  7. OpenStack IceHouse版cinder模块新添加功能

    感谢朋友支持本博客.欢迎共同探讨交流.因为能力和时间有限.错误之处在所难免,欢迎指正! 假设转载,请保留作者信息. 博客地址:http://blog.csdn.net/gaoxingnengjisua ...

  8. HDU 3065 病毒侵袭持续中(AC自己主动机)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3065 Problem Description 小t非常感谢大家帮忙攻克了他的上一个问题.然而病毒侵袭 ...

  9. Linux安装配置Redis CentOS 7 下安装Redis

    Redis是一个高性能的,开源key-value型数据库.是构建高性能,可扩展的Web应用的完美解决方案,可以内存存储亦可持久化存储.因为要使用跨进程,跨服务级别的数据缓存,在对比多个方案后,决定使用 ...

  10. Centos6.5 安装 Oracle11gR2(64位)

    Centos6.5安装 Oracle11gR2(64位) 安装centos6.5 (我的是虚拟机环境) 1.  下载centos6.5的安装包,不解释. 例如以下图: 2.  下载oracle安装包, ...