POJ 3970:Party

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

 Status

Description

The CEO of ACM (Association of Cryptographic Mavericks) organization has invited all of his teams to the annual all-hands meeting, being a very disciplined person, the CEO decided to give a money award to the first team that shows up to the meeting. 

The CEO knows the number of employees in each of his teams and wants to determine X the least amount of money he should bring so that he awards the first team to show up such that all team members receive the same amount of money. You must write a program to help the CEO achieve this task.

Input

The input consists of multiple test cases, each test case is described on a line by itself, Each line starts with an integer N (1 <= N <= 20) the number of teams in the organization followed by N space separated positive integers representing the number of employees in each of the N teams. You may assume that X will always fit in a 32 bit signed integer. The last line of input starts with 0 and shouldn't be processed.

Output

For each test case in the input print "The CEO must bring X pounds.", where X is as described above or "Too much money to pay!" if X is 1000000 or more. 

Sample Input

1 3000000
2 12 4
0

Sample Output

Too much money to pay!
The CEO must bring 12 pounds.

题意就是找各个数的最小公倍数。。。大于1000000的就输出too much。。。

水。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std;

int yue,cur,num,i,flag;
int test[200];

long long MaxY(long long x,long long y)
{

	if (!x || !y)
		return x > y ? x : y;
	for (long long t; t = x % y; x = y, y = t)
		;
	return y;
} 

long long cal(long long a,long long b)
{
	return (a*b)/yue;
}


int main()
{
	//freopen("i.txt","r",stdin);
	//freopen("o.txt","w",stdout);
	while(1)
	{
		cin>>num;
		if(num==0)
			break;
		flag=1;
		cur=1;
		for(i=1;i<=num;i++)
		{
			cin>>test[i];
			if(flag)
			{
				yue=MaxY(cur,test[i]);
				cur=cal(cur,test[i]);
			}
			if(cur>=1000000)
			{
				flag=0;
			}
		}
		if(flag)
			cout<<"The CEO must bring "<<cur<<" pounds."<<endl;
		else
			cout<<"Too much money to pay!"<<endl;
	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

posted on 2015-07-24 10:56  光速小子  阅读(396)  评论(0编辑  收藏  举报

导航