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; ...
随机推荐
- php中GD库的简单使用
在php中需要图像处理的地方GD库会发挥重要的作用,php可以创建并处理包括GIF,PNG,JPEG,WBMP以及XPM在内的多种图像格式,简单的举几个例子: 1.用GD库会创建一块空白图片,然后绘制 ...
- 【JAVA、C++】LeetCode 010 Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...
- DP:Wooden Sticks(POJ 1065)
摆木棍 题目大意:即使有一堆木棍,给一个特殊机器加工,木棍都有两个属性,一个是l一个是w,当机器启动的时候(加工第一根木棒的时候),需要一分钟,在这以后,设机器加工的上一根木棒的长度是l,质量是w,下 ...
- js如何往数组Array中添加元素
转载自:http://blog.sina.com.cn/s/blog_95fa28e60101mwup.html unshift:将参数添加到原数组开头,并返回数组的长度 pop:删除原数组最后一项 ...
- HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)
Sum Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u Submit Status ...
- [Ant] Ant之MacroDef—“宏
转载自:http://lhq1013.iteye.com/blog/1157234 Ant是一个基于Java的跨平台构建工具,它易于使用,并且可扩展.可升级. MacroDef——“宏”,在An ...
- Java编程设计2
一般我们会以这种设计方式生产对象实例,如: 创建一个接口: public interface TestOpen { String getVirtualHost(); String getCapabil ...
- ScrollView与TableView实现选择效果
在cocos2dx中,ScrollView与TableView都可以实现选择效果,其中ScrollView较为原始,TableView的格子大小可以不与winSize一样大. ScrollView实现 ...
- php 的函数参数值类型限定
如例: function test(array $a,test $b){ /*...*/ } class test{ /*...*/ } test(array(),new test); 表示test函 ...
- win32_11gR2_database安装教程