题目链接

虽然我不懂...

 #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. MySql的like语句中的通配符:百分号、下划线和escape

      MySql的like语句中的通配符:百分号.下划线和escape   %:表示任意个或多个字符.可匹配任意类型和长度的字符. Sql代码 select * from user where user ...

  2. jstack命令详解

    jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,如果是在64位机器上,需要指定选项"-J-d64",Windows的jstack使 ...

  3. 什么是iis服务器

    IS 是Internet Information Server的缩写,它是微软公司主推的服务器,最新的版本是Windows2003里面包含的IIS 6.0,IIS与WindowNT Server完全集 ...

  4. spring无法扫描jar包的问题

    在日常开发中往往会对公共的模块打包发布,然后调用公共包的内容.然而,最近对公司的公共模块进行整理发布后.spring却无法扫描到相应的bean.折腾了好久,最终发现是认识上的误区. 2015-11-1 ...

  5. codeforces A. IQ Test 解题报告

    题目链接:http://codeforces.com/problemset/problem/328/A 一开始单纯地直接判断给出的序列是等差还是等比,连这一句“You should also prin ...

  6. 【USACO】pprime

    开始看第一眼题就觉得问题会在超时上,果然写了个小代码运行到test 9时超时了 #include <stdio.h> #include <math.h> int isprime ...

  7. [MAC] SVN lock的使用

    转载 : http://www.eefocus.com/czzheng/blog/12-03/245532_4ca94.html 如果压根没有锁lock,那么每个人都拥有一个本地copy,每个人都能自 ...

  8. bootstrap学习总结1

    什么是Bootstrap? bootstrap就是一个前端框架,有Twitter公司开发 最大的优点: 开源 : 响应式设计:Bootstrap 的响应式 CSS 能够自适应于台式机.平板电脑和手机. ...

  9. error: Refusing to undefine while domain managed save image exists

    [root@ok libvirt]# virsh undefine win7 error: Refusing to undefine while domain managed save image e ...

  10. IIS7 / IIS7.5 URL 重写 HTTP 重定向到 HTTPS(转)

    转自: http://www.cnblogs.com/yipu/p/3880518.html   1.购买SSL证书,参考:http://www.cnblogs.com/yipu/p/3722135. ...