POJ 1006_Biorhythms
来源:互联网 发布:手机全局透明软件 编辑:程序博客网 时间:2024/05/21 00:50
本题没什么编程难点,主要就是采用了中国剩余定理解题。
在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。下面说说我对该定理的理解。
首先确定3,5,7为俩俩互质的数,找出3和5的公倍数中最小的能使它%7=1的数,再找出3和7的公倍数中最小的能使它%5=1的数,最后找出5和7的公倍数中最小的能使它%3=1的数,它们是15,21,70。用着三个数分别乘以他们所取余的数7,5,3在题目中的余数2,3,2然后求和,之后再用这个所求的和取余3,5,7的最小公倍数105。即15*2+21*3+70*2=233,233%105=23。so,23即为所求。
...具体代码如下
#include <iostream>#include <cmath>using namespace std;int main(){int p, e, i, d, kase = 0;while (cin >> p >> e >> i >> d){if (p == -1 && e == -1 && i == -1 && d == -1)break;int ans = (1288 * i + 14421 * e + 5544 * p - d) % (23 * 28 * 33);if (ans <= 0)ans += 23 * 28 * 33;cout << "Case " << ++kase << ": the next triple peak occurs in " << ans << " days." << endl;}return 0;}
0 0
- POJ 1006_Biorhythms
- POJ[1006]
- POJ 1006
- poj 1006
- poj 1006
- poj 1006
- POJ 1006
- poj 1006
- poj 1006
- POJ-1006
- poj 1006
- POJ 1006
- poj 1006
- POJ 1006
- POJ-1006
- POJ 1006
- POJ 1006
- poj--1006
- Redhat El7.2硬盘安装
- 设计模式-备忘录模式
- 如何实现一个搜索引擎(2):查询索引 How to Implement a Search Engine Part 2: Query Index
- compile sslsplit
- keepalived应用
- POJ 1006_Biorhythms
- uwsgi启动
- apache服务器
- Android——ViewHolder简洁写法
- 第1章第1节练习题4 有序表删除指定区间值
- 剑指offer-数值的整数次方
- mysql的默认排序
- ss
- RabbitMQ基础知识