POJ1006——中国剩余定理
题目:http://poj.org/problem?id=1006
中国剩余定理:x= m/mj + bj + aj 讲解:http://www.cnblogs.com/MashiroSky/p/5918158.html
逆元:m/mj * bj -mj *y=1——m/mj * bj = 1 mod mj
拓展欧几里得:p*a+q*b=gcd(a,b)——p'=q ; q'=p - a/b * q
#include<iostream>
#include<cstdio>
using namespace std;
int a1,a2,a3,m1=,m2=,m3=,mm1=,mm2=,mm3=,m=,st;
int x,y,k,t;
void exgcd(int a,int b)
{
if(!b)
{
x=;
y=;
return;
}
exgcd(b,a%b);
int tem=y;
y=x-a/b*y;
x=tem;
}
int main()
{
while()
{
k=;t++;
scanf("%d%d%d%d",&a1,&a2,&a3,&st);
if(a1==-&&a2==-&&a3==-&&st==-)break;
a1%=m1;a2%=m2;a3%=m3;
exgcd(mm1,m1);
k+=mm1*a1*x;k%=m;
exgcd(mm2,m2);
k+=mm2*a2*x;k%=m;
exgcd(mm3,m3);
k+=mm3*a3*x;k%=m;
while(k<=st)k+=m;
k-=st;
printf("Case %d: the next triple peak occurs in %d days.\n",t,k);
}
return ;
}
POJ1006——中国剩余定理的更多相关文章
- poj1006中国剩余定理
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103506 Accepted: 31995 Des ...
- POJ1006 Biorhythms —— 中国剩余定理
题目链接:https://vjudge.net/problem/POJ-1006 Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total ...
- 《孙子算经》之"物不知数"题:中国剩余定理
1.<孙子算经>之"物不知数"题 今有物不知其数,三三数之剩二,五五数之剩七,七七数之剩二,问物几何? 2.中国剩余定理 定义: 设 a,b,m 都是整数. 如果 m ...
- POJ 1006 中国剩余定理
#include <cstdio> int main() { // freopen("in.txt","r",stdin); ; while(sca ...
- [TCO 2012 Round 3A Level3] CowsMooing (数论,中国剩余定理,同余方程)
题目:http://community.topcoder.com/stat?c=problem_statement&pm=12083 这道题还是挺耐想的(至少对我来说是这样).开始时我只会60 ...
- (伪)再扩展中国剩余定理(洛谷P4774 [NOI2018]屠龙勇士)(中国剩余定理,扩展欧几里德,multiset)
前言 我们熟知的中国剩余定理,在使用条件上其实是很苛刻的,要求模线性方程组\(x\equiv c(\mod m)\)的模数两两互质. 于是就有了扩展中国剩余定理,其实现方法大概是通过扩展欧几里德把两个 ...
- 洛谷P2480 [SDOI2010]古代猪文(费马小定理,卢卡斯定理,中国剩余定理,线性筛)
洛谷题目传送门 蒟蒻惊叹于一道小小的数论题竟能涉及这么多知识点!不过,掌握了这些知识点,拿下这道题也并非难事. 题意一行就能写下来: 给定\(N,G\),求\(G^{\sum \limits _{d| ...
- 洛谷P3868 [TJOI2009]猜数字(中国剩余定理,扩展欧几里德)
洛谷题目传送门 90分WA第二个点的看过来! 简要介绍一下中国剩余定理 中国剩余定理,就是用来求解这样的问题: 假定以下出现数都是自然数,对于一个线性同余方程组(其中\(\forall i,j\in[ ...
- POJ2891 Strange Way to Express Integers 扩展欧几里德 中国剩余定理
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ2891 题意概括 给出k个同余方程组:x mod ai = ri.求x的最小正值.如果不存在这样的x, ...
随机推荐
- 使用路径arc-七彩
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- spring cloud图形化dashboard是如何实现指标的收集展示的
spring cloud图形化dashboard是如何实现指标的收集展示的 1.dashboard图形化界面入口 http://localhost:10000/hystrix.stream 说明:端口 ...
- splunk LB和scale(根本在于分布式扩展index,search)
Forwarder deployment topologies You can deploy forwarders in a wide variety of scenarios. This topic ...
- bzoj1648
题解: 简单灌水 然后统计一下 代码: #include<bits/stdc++.h> using namespace std; ; int ne[N],num,fi[N],n,k,m,x ...
- python3 win10_x64 安装pcapy
稀里糊涂就装上了 大概记录一下都有什么. visual studio build tools 2015 下载地址: http://landinghub.visualstudio.com/visual- ...
- ant 打 jar 包添加 manifest.mf 文件
经查询 ant 有 <manifest> 任务可以创建 manifest文件(https://ant.apache.org/manual/Tasks/manifest.html) 但尝试在 ...
- DevExpress v18.1最新版帮助文档下载大全
DevExpress v18.1.4帮助文档下载列表大全来啦!包含.NET.VCL.HTML/JS系列所有帮助文档,提供CHM和PDF两个版本.除已停止更新的Silverlight.Windows 8 ...
- hibernate 各种主键生成策略(转)
http://www.cnblogs.com/kakafra/archive/2012/09/16/2687569.html 1.assigned 主键由外部程序负责生成,在 save() 之前必须指 ...
- L210 Ebola
Progress in fighting Democratic Republic of the Congo's Ebola outbreak, the second worst ever, will ...
- MovingBoxes左右滑动放大图片插件
MovingBoxes左右滑动放大图片插件在产品预览时很有用哦 实例代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition ...