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

大水题竟然搞了一次RE。。。注意计算过程中如果已经超了1000000,之后的数还要继续读入。。。

Posted by KatrineYang at 2017-01-23 05:47:37 on Problem 3970
#include <iostream>
using namespace std;

int GCD(int a, int b){
	if(!a) return b;
	if(!b) return a;
	if(a<b) return GCD(a, b%a);
	return GCD(b, a%b);
}

int LCM(int a, int b){
	return a/GCD(a,b)*b;
}

int main() {
	while(1){
		int n;
		cin >> n;
		if(!n) break;
		int num = 1;
		bool ky = true;
		for(int i = 0; i < n; i++){
			int tmp;
			cin >> tmp;
			if(ky) num = LCM(num,tmp);
			if(num>=1000000) ky = false;//如果这里直接break就是RE
		}
		//cout << num << endl;
		if(!ky) cout << "Too much money to pay!" << endl;
		else cout << "The CEO must bring " << num << " pounds." << endl;
	}
	return 0;
}

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