中国剩余定理 POJ 1006 Biorhythms
题意:POJ有中文题面
分析:其实就是求一次同余方程组:(n+d)=p(%23), (n+d)=e(%28), (n+d)=i(%33),套用中国剩余定理模板
代码:
/************************************************
* Author :Running_Time
* Created Time :2015/9/15 星期二 16:53:01
* File Name :POJ_1006.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
ll f[N];
int n; ll multi_mod(ll a, ll b, ll p) { //a * b % p
a = (a % p + p) % p;
b = (b % p + p) % p;
ll ret = 0;
while (b) {
if (b & 1) {
ret += a;
if (ret >= p) ret -= p;
}
b >>= 1;
a <<= 1;
if (a >= p) a -= p;
}
return ret;
} ll ex_GCD(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1; y = 0; return a;
}
ll d = ex_GCD (b, a % b, y, x);
y -= x * (a / b);
return d;
} ll China(int k, int *b, int *m) {
ll M = 1, x, y, ret = 0;
for (int i=1; i<=k; ++i) M *= m[i];
for (int i=1; i<=k; ++i) {
ll w = M / m[i];
ex_GCD (w, m[i], x, y);
ret += b[i] * (x * w % M) % M;
}
return (ret - n + M) % M;
} int main(void) {
int b[4], m[4];
m[1] = 23; m[2] = 28; m[3] = 33;
int cas = 0;
while (scanf ("%d%d%d%d", &b[1], &b[2], &b[3], &n) == 4) {
if (b[1] == -1 && b[2] == -1 && b[3] == -1 && n == -1) break;
ll ans = China (3, b, m);
if (ans == 0) ans = 21252;
printf ("Case %d: the next triple peak occurs in %I64d days.\n", ++cas, ans);
} return 0;
}
中国剩余定理 POJ 1006 Biorhythms的更多相关文章
- POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)
POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- POJ 1006 Biorhythms --中国剩余定理(互质的)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103539 Accepted: 32012 Des ...
- POJ 1006 Biorhythms (数论-中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 111285 Accepted: 34638 Des ...
- PKU POJ 1006 Biorhythms (中国剩余定理)
中国剩余定理 x = ai (mod mi) ai和mi是一组数,mi两两互质,求x 令Mi = m1*m2*~mk 其中,mi不包含在内. 因为mi两两互质,所以存在x和y, st M ...
随机推荐
- html使用代码大全
<DIV style="FONT-SIZE: 9pt">1)贴图:<img src="图片地址">1)首行缩进2格:<p styl ...
- BingMap地图怎样显示中文
这是bingMap的js引用 <script type="text/javascript" src="v=7.0&mkt=zh-cn'></sc ...
- hdfs 3种 通讯协议
http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_design.html 通讯协议 所有的HDFS通讯协议都是建立在TCP/IP协议之上.客户端通过一个可配置的 ...
- 关于div li 等标签之间自带间距
可以用float来清除标签之间的间距. ps :ul使用font-size:0 唯一的缺点就是要再次设置LI的font-size
- MYSQL进阶学习笔记三:MySQL流程控制语句!(视频序号:进阶_7-10)
知识点四:MySQL流程控制语句(7-10) 选择语句: (IF ELSE ELSE IF CASE 分支)IFNULL函数 IF语法: 语法规则: IF search_condition THEN ...
- 用 javascript 操作 xml
1. [代码]js代码 <script language="JavaScript"><!--var doc = new ActiveXObject(&qu ...
- iOS中键盘的收起
在UIViewController中收起键盘,除了调用相应控件的resignFirstResponder方法之外,还有另外三种方法: 重载UIViewController中的touchesBegin方 ...
- [SHOI 2015] 脑洞治疗仪
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4592 [算法] 对于操作1 , 我们首先查询区间[l0 , r0]中有多少个1 , ...
- ASP.NET Core:template
ylbtech-ASP.NET Core: 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://yl ...
- Meta标签中的format-detection属性及含义(转)
一.Meta标签中的format-detection属性及含义 意为:格式检测 或许你会有这样的经历:当你在制作手机端的页面中,点击了没有加任何链接的格式的数字时,这时手机会进行自动拔号提示操作! 禁 ...