Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
C++#include <iostream> #include <stdlib.h> using namespace std; int gcd(int x, int y); //最大公约数 int main(void) { int p, e, i, d,n=0; int x = 23 * 28 * 33 / gcd(gcd(23, 28), 33); //最小公倍数 int passDay = 0;//目标天数 while (cin >> p >> e >> i >> d){ if (p == -1 && e == -1 && i == -1 & d == -1) break; n++; for (int k = 0; k < x; k++) if (k% 23 ==p%23 && k%28==e%28 && k % 33 == i%33) { passDay = k; break; } if (passDay <= d) passDay += x; printf("Case %d: the next triple peak occurs in %d days.\n", n, passDay - d); } system("pause"); return 0; } int gcd(int x, int y){ if (y == 0) return x; if (x > y) return gcd(y, x%y); else return gcd(x, y%x); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator