hdu 2028 Lowest Common Multiple Plus

一道很简单的题,由于自己没有理解清题意,而屡次wrong answer...悲剧。。审题啊审题。。

题的思路是,先求两个数的最小公倍数,再把求的数与接下来的一个数一起求最小公倍数...依次下去,直到最后一个....

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
__int64 fun(__int64 x,__int64 y)
{
   __int64 temp;
   if(x<y)
   {
   temp=x;
   x=y;
   y=temp;
   }
   __int64 r,p;
   p=x*y;
   while(y)
   {
   r=x%y;
   x=y;
   y=r; 
   }
   
   return p/x;
} 
int main( )
{
  int N,i;
  while(scanf("%d",&N)!=EOF)
  {
   
    __int64 sum=1, A[100000],t,i,j,k;
   
   for(i=0;i<N;i++)
     scanf("%I64d",&A[i]);
   if(N>=2)
   { 
     t=fun(A[0],A[1]);
   //for(i=0;i<N;i++)
    //sum*=A[i]; 
    for(i=2;i<N;i++)
     {
    
      //if(i==N-1)
      //sum=t*A[i-1];
      t=fun(t,A[i]);
     }
     
     printf("%I64d\n",t);
   }
   //else
  // printf("%I64d\n",A[0]);
     
}
//system("pause");
return 0;
}

posted on 2011-03-30 23:54  more think, more gains  阅读(222)  评论(0编辑  收藏  举报

导航