题目链接

虽然我不懂...

 #include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
using namespace std;
#define LL __int64
LL p[],o[];
LL x,y;
LL ext_eulid(LL a,LL b)
{
LL t,d;
if(b == )
{
x = ;
y = ;
return a;
}
d = ext_eulid(b,a%b);
t = x;
x = y;
y = t - (a/b)*y;
return d;
}
LL gcd(LL a,LL b)
{
return b == ?a:gcd(b,a%b);
}
int main()
{
int i,n,z;
LL p1,o1,d,c,mod;
while(scanf("%d",&n)!=EOF)
{
for(i = ;i < n;i ++)
{
scanf("%I64d%I64d",&p[i],&o[i]);
}
p1 = p[];
o1 = o[];
z = ;
for(i = ;i < n&&z;i ++)
{
d = ext_eulid(p1,p[i]);
c = o[i] - o1;
if(c%d) z = ;
mod = p[i]/d;
x = ((c/d*x)%mod+mod)%mod;
o1 = p1*x + o1;
p1 = p1*mod;
}
if(!z)
printf("-1\n");
else
printf("%I64d\n",o1);
}
return ;
}

POJ 2891 Strange Way to Express Integers(中国剩余定理)的更多相关文章

  1. POJ 2891 Strange Way to Express Integers 中国剩余定理 数论 exgcd

    http://poj.org/problem?id=2891 题意就是孙子算经里那个定理的基础描述不过换了数字和约束条件的个数…… https://blog.csdn.net/HownoneHe/ar ...

  2. POJ 2891 Strange Way to Express Integers 中国剩余定理解法

    一种不断迭代,求新的求余方程的方法运用中国剩余定理. 总的来说,假设对方程操作.和这个定理的数学思想运用的不多的话.是非常困难的. 參照了这个博客的程序写的: http://scturtle.is-p ...

  3. poj 2981 Strange Way to Express Integers (中国剩余定理不互质)

    http://poj.org/problem?id=2891 Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 13 ...

  4. poj 2891 Strange Way to Express Integers (非互质的中国剩余定理)

    Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9472   ...

  5. poj——2891 Strange Way to Express Integers

    Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 16839 ...

  6. [POJ 2891] Strange Way to Express Integers

    Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 10907 ...

  7. poj 2891 Strange Way to Express Integers(中国剩余定理)

    http://poj.org/problem?id=2891 题意:求解一个数x使得 x%8 = 7,x%11 = 9; 若x存在,输出最小整数解.否则输出-1: ps: 思路:这不是简单的中国剩余定 ...

  8. [poj 2891] Strange Way to Express Integers 解题报告(excrt扩展中国剩余定理)

    题目链接:http://poj.org/problem?id=2891 题目大意: 求解同余方程组,不保证模数互质 题解: 扩展中国剩余定理板子题 #include<algorithm> ...

  9. poj 2891 Strange Way to Express Integers【扩展中国剩余定理】

    扩展中国剩余定理板子 #include<iostream> #include<cstdio> using namespace std; const int N=100005; ...

随机推荐

  1. Linux 制作ftp远程yum仓库

    一.下载createrepo yum install createrepo -y 二.安装vsftp软件 yum install vsftpd -y 三.将pub制作为yum仓库 把需要的rpm包拷贝 ...

  2. LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android

    LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android jincon 发表于 2015-02-26 18:31:01 发表在: php开发 localresiz ...

  3. Python的getattr()

    Python的getattr(),setattr(),delattr(),hasattr() getattr()函数是Python自省的核心函数,具体使用大体如下: 获取对象引用getattrGeta ...

  4. 【云计算】开源的Docker Registry WebUI

    kwk/docker-registry-frontend   Code       Issues         9       Pull requests       6       Wiki   ...

  5. 《转》VS2012发布网站详细步骤

    本文转载自MannyGuo 如果给您带来不便请联系博主 1.打开你的VS2012网站项目,右键点击项目>菜单中 重新生成一下网站项目:再次点击右键>发布: 2.弹出网站发布设置面板,点击& ...

  6. 《ASP.NET1200例》实现投票的用户控件

    用户控件ascx <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="24 ...

  7. 【转】maven导出项目依赖的jar包

    本文转自:http://my.oschina.net/cloudcoder/blog/212648 一.导出到默认目录 targed/dependency 从Maven项目中导出项目依赖的jar包:进 ...

  8. iOS7 中的statusbar的隐藏和样式更改

    ios7以前,如果想要隐藏statusbar,需要用到[UIApplicationsharedApplication].statusBarHidden = YES; 或者在plist文件中设定Stat ...

  9. 用php实现遍历目录

    用php实现的遍历目录,只遍历第一层,如果制作在线文件管理器的话很管用,不同目录只加一个超链接就行了,然后给方法传递参数就行了,遍历目录的类如下: class Ergodic{ public func ...

  10. canvas API ,通俗的canvas基础知识(五)

    前几期讲的都是路径图形的绘图,这节我们要讲的是如何在画布上操作图片,因为图形画不了漂亮妹子(画图高手忽略不计),想画美女怎么办?跟我来: 想要在画布中插入一张图片,我们需要的方法是这位大侠: draw ...