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; }
思考: 今天看了看推理过程, 觉得挺有意思的, 好好学数学
另外感谢楼主对中国剩余定理的详细解释, 让我一个弱鸡看得明白: http://www.cnblogs.com/walker01/archive/2010/01/23/1654880.html
posted on 2017-08-17 17:12 FriskyPuppy 阅读(172) 评论(0) 编辑 收藏 举报