设为首页 加入收藏

TOP

UVA 756 - Biorhythms(数论)
2015-07-24 05:53:45 来源: 作者: 【 】 浏览:5
Tags:UVA 756 Biorhythms 数论

756 - Biorhythms

题目链接

基本就是裸的中国剩余定理。

代码:

#include 
  
   
#include 
   
     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; }
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇bnu 34981 A Matrix(构造) 下一篇Design Pattern Iterator 迭代器..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: