POJ 2891 Strange Way to Express Integers(中国剩余定理)
虽然我不懂...
#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(中国剩余定理)的更多相关文章
- POJ 2891 Strange Way to Express Integers 中国剩余定理 数论 exgcd
http://poj.org/problem?id=2891 题意就是孙子算经里那个定理的基础描述不过换了数字和约束条件的个数…… https://blog.csdn.net/HownoneHe/ar ...
- POJ 2891 Strange Way to Express Integers 中国剩余定理解法
一种不断迭代,求新的求余方程的方法运用中国剩余定理. 总的来说,假设对方程操作.和这个定理的数学思想运用的不多的话.是非常困难的. 參照了这个博客的程序写的: http://scturtle.is-p ...
- poj 2981 Strange Way to Express Integers (中国剩余定理不互质)
http://poj.org/problem?id=2891 Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 13 ...
- poj 2891 Strange Way to Express Integers (非互质的中国剩余定理)
Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9472 ...
- poj——2891 Strange Way to Express Integers
Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 16839 ...
- [POJ 2891] Strange Way to Express Integers
Strange Way to Express Integers Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 10907 ...
- poj 2891 Strange Way to Express Integers(中国剩余定理)
http://poj.org/problem?id=2891 题意:求解一个数x使得 x%8 = 7,x%11 = 9; 若x存在,输出最小整数解.否则输出-1: ps: 思路:这不是简单的中国剩余定 ...
- [poj 2891] Strange Way to Express Integers 解题报告(excrt扩展中国剩余定理)
题目链接:http://poj.org/problem?id=2891 题目大意: 求解同余方程组,不保证模数互质 题解: 扩展中国剩余定理板子题 #include<algorithm> ...
- poj 2891 Strange Way to Express Integers【扩展中国剩余定理】
扩展中国剩余定理板子 #include<iostream> #include<cstdio> using namespace std; const int N=100005; ...
随机推荐
- SHSEE 备战最后十(四)天日记
努力. Day -1 看书.睡觉. Day 0 上午考试.语文纯RP题跪.理总不错. 下午上课,各种神. Day 1 上午下午讲课...Day 0成绩出来才#17.... Day 2 考试..这次题目 ...
- ubuntu14.04 中国源
deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiversedeb http://cn.arc ...
- Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- lambda 表达式
C++0x 的语法还是比较简单.下面通过几个例子来介绍下. 先是通过 std::for_each 演示一个简单的例子: ? std::for_each 和 lambda 1 2 3 4 5 6 7 8 ...
- Java for LeetCode 165 Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...
- atom初体验
今天捣鼓了一天的atom,也测试了那个传说中绚丽的敲代码方式,感觉就是装逼利器,这里总结一下今天捣鼓的过程吧 首页,下载atom,这个在地址是:搜索 之后是安装插件,在这之前如果下载的是.exe的,那 ...
- glut编译问题 (程序无法运行)
参考:http://blog.csdn.net/robinjwong/article/details/5636049 error: the procedure entry point _glutini ...
- etc目录名字的意思---挖Linux中的古老缩略语
Unix已经有35年历史了.许多人认为它开始于中世纪,这个中世纪是相对于计算机技术的产生和发展来说的.在过去的时间里,Unix和它的子分支Linux收集有许多的历史和一些完全古老的语言.在这篇技巧文章 ...
- hdu 1010:Tempter of the Bone(DFS + 奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 怎么判定一个mac地址是multicast还是unicast.
MAC地址是以太网二层使用的一个48bit(6字节十六进制数)的地址,用来标识设备位置.MAC地址分成两部分,前24位是组织唯一标识符(OUI, Organizationally unique ide ...