POJ-1006-Biorhythms
2014-07-12 15:42
363 查看
核心思想:
利用孙子定理解同余方程组来求解。
注记:
1、源码(C)
2、目前对于同余方程组的求解是手工计算的,应通过代码来实现一下。
3、此题可以扩展为把23、28、33等类似的两两互素的数字也作为输入项,而且也可以不局限在只有三个数,可以更多两两互素的数。
利用孙子定理解同余方程组来求解。
注记:
1、源码(C)
#include <stdio.h> #define MOD 21252 int biorhythms(int, int, int, int); int main() { int p, e, i, d, j = 1; while (1) { scanf("%d%d%d%d", &p, &e, &i, &d); if (p == -1 && e == -1 && i == -1 && d == -1) { break; } printf("Case %d: the next triple peak occurs in %d days.\n", j++, biorhythms(p, e, i, d)); } return 0; } int biorhythms(int p, int e, int i, int d) { int bior; // 47MS bior = (28 * 33 * 6 * p + 23 * 33 * 19 * e + 23 * 28 * 2 * i) % MOD; // 16MS //bior = (5544 * p + 14421 * e + 1288 * i) % MOD; if (bior <= d) { bior = MOD + bior - d; } else { bior -= d; } return bior; }
2、目前对于同余方程组的求解是手工计算的,应通过代码来实现一下。
3、此题可以扩展为把23、28、33等类似的两两互素的数字也作为输入项,而且也可以不局限在只有三个数,可以更多两两互素的数。
相关文章推荐
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms 中国剩余定理
- POJ 1006 Biorhythms(中国剩余定理)
- POJ 1006 Biorhythms 中国剩余定理
- POJ 1006 Biorhythms (中国剩余定理)
- POJ 1006 Biorhythms: 孙子定理
- [poj] 1006 Biorhythms
- POJ 1006.Biorhythms
- POJ 1006 Biorhythms [中国剩余定理] 超短代码
- POJ_1006_Biorhythms
- poj1006 Biorhythms
- poj 1006 Biorhythms(两种做法)
- POJ_1006_Biorhythms
- Poj 1006 Biorhythms
- POJ-----1006---Biorhythms扩展欧几里得
- POJ 1006 Biorhythms
- POJ1006 Biorhythms(生理周期,中国剩余定理详述)
- poj 1006 Biorhythms
- 【POJ】1006 Biorhythms
- POJ 1006 Biorhythms 中国剩余定理