UVA 756 - Biorhythms(数论)
2014-06-25 19:37
274 查看
756 - Biorhythms
题目链接基本就是裸的中国剩余定理。
代码:
#include <stdio.h>
#include <string.h>
const int M = 23 * 28 * 33;
const int m[3] = {23, 28, 33};
int p[3], d;
int gcd(int a, int b, int &x, int &y) {
if (!b) {x = 1; y = 0; return a;}
int d = gcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
int main() {
int cas = 0;
while (~scanf("%d%d%d%d", &p[0], &p[1], &p[2], &d)) {
if (p[0] < 0 && p[1] < 0 && p[2] < 0 && d < 0) break;
int ans = 0;
for (int i = 0; i < 3; i++) {
int x, y, w = M / m[i];
gcd(m[i], w, x, y);
ans = (ans + p[i] % m[i] * w * y) % M;
}
ans -= d;
if (ans <= 0) ans += M;
printf("Case %d: the next triple peak occurs in %d days.\n", ++cas, ans);
}
return 0;
}
相关文章推荐
- UVA, 756 Biorhythms
- POJ1006 UVA756 UVALive5421 Biorhythms【中国剩余定理】
- uva 756—— Biorhythms
- uva 756 - Biorhythms(中国剩余定理)
- uva 10693 - Traffic Volume(数论)
- 数论:欧拉函数 uva 10820
- UVA 10253 - Series-Parallel Networks(数论+计数问题+递推)
- uva12111(数论-2进制)
- UVa 11752 - The Super Powers (数论)
- Again Prime? No Time.(uva10870+数论)
- POJ 1006 Biorhythms (数论-中国剩余定理)
- UVA 10368 - Euclid's Game(数论+博弈)
- UVA 1521 - GCD Guessing Game(数论+贪心)
- Uva 11971 Polygon(数论、概率)
- UVA 11754 - Code Feat(数论)
- uva 11014 - Make a Crystal(数论)
- uva 10581 - Partitioning for fun and profit(记忆化搜索+数论)
- UVA 11773 King's Wish(数论)
- uva 10726 Coco Monkey(数论)
- UVa 694 The Collatz Sequence (数论)