POJ 1006 Biorhythms 中国剩余定理 数论

  题目链接: http://poj.org/problem?id=1006

  题目大意: 给你三个数p e i 让你求一个x 使得 x % 23 == p, x % 28 == e, x % 33 == i

  解题思路: 裸的中国剩余定理

  代码: 

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iterator>
#include <cmath>
#include <algorithm>
#include <stack>
#include <deque>
#include <map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
typedef long long ll;
using namespace std;

//const int INF = 0x3fffffff;
ll gcd( ll a, ll b ) {
    return b == 0 ? a : gcd( b, a % b );
}

ll lcm( ll a, ll b ) {
    return a / gcd(a, b) * b;
}

int main() {
//    cout << lcm( lcm(23, 28), 33 ) << endl;
    ll p, e, i, d;
    int cases = 1;
    while( cin >> p >> e >> i >> d ) {
        if( p == -1 && e == -1 && i == -1 && d == -1 ) break;
        ll ans = 5544 * p + 14421 * e + 1288 * i - d;
        ans %= 21252;
        if( ans <= 0 ) ans += 21252;
        cout << "Case " << cases++ << ": the next triple peak occurs in " << ans << " days." << endl;
    }
    return 0;
}
View Code

  思考: 今天看了看推理过程, 觉得挺有意思的, 好好学数学

  另外感谢楼主对中国剩余定理的详细解释, 让我一个弱鸡看得明白: http://www.cnblogs.com/walker01/archive/2010/01/23/1654880.html

转载于:https://www.cnblogs.com/FriskyPuppy/p/7382860.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值