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

请问3002是否是一个求最大公倍数问题

Posted by xdd__1986 at 2009-09-15 21:26:56
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

	int getw(int a,int b)//两个数的最大公约数
	{
		int temp,r;
		if(a<b)
		{
			temp=a;
			a=b;
			b=temp;
		}
		while(b)
		{
		   r=a%b;
		   a=b;
		   b=r;
		}
		return a;
	}

	int getm(int m,vector<int>& a)
	{
		vector<int> b;
		if(m>2){
			b.push_back(getw(a[0],a[1]));
			for(int i=1;i<m-1;i++)
			{
				b.push_back(a[i+1]);
			}
			return getm(m-1,b);
		}
		else
			return getw(a[0],a[1]);
	}
	
   long	 work(int m,vector<int>& a)
   {
		 vector<int> b;   
		  if(m>2)   
		  {   
			  b.push_back(a[0]*a[1]/getw(a[0],a[1]));   
			  for(int i=1;i<m-1;i++)   
			  {   
				 b.push_back(a[i+1]);   
			  }   
			  return work(m-1,b);   
		  }   
		  else  return a[0]*a[1]/getw(a[0],a[1]); 
	}

	int main()
	{
		vector<int> a;
		int i,j;
	    long number,sum=1;
	
     	for(i=0;i<9;i++)
		{
	     	sum=sum*10;
		}
			int n,m;//n是机器数m是该机器的轮子数;
				cin>>n;
				for(i=0;i<n;i++)
				{
					cin>>m;
					for(j=0;j<m;j++)
					{
						int tmp;
					   cin>>tmp;
					   a.push_back(tmp);
					}
					number=work(m,a);
					if(number<sum)
						cout<<number<<endl;
					else 
						cout<<"More than a billion."<<endl;
				}

			
		return 0;
	}
这是之前有位老兄做的 我帮他看了半天也不知为何wa

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