Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

C++

Posted by freelark at 2016-10-29 20:03:58 on Problem 1006
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator