POJ 3970:Party

30 篇文章 0 订阅

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;
}


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值