#1204: 要怎麼加速 不逾時


morris1028 (碼畜)


#include<stdio.h>  
#include<stdlib.h>
#include<string.h>
int gcd(int a,int b)
 {
  int temp;
  while(a%b)     
   {     
    temp=a;     
    a=b;     
    b=temp%b;                
   }
   return b;
 }
char x[100000000];
int y[100000000];
main()
{
 int a,b,c,temp1,time;
 int lcm;
 while(gets(x)!=0)
  {
  if(x[0]=='0'&&strlen(x)==1) break;
   time=0;temp1=0;lcm=1;
  for(c=0;c<=strlen(x);c++)          /*不存在X[strlen(c)]*/
   {
   if(x[c]<=57&&x[c]>=48)
    temp1=temp1*10+x[c]-48;
   else
    {y[time]=temp1;time++;temp1=0;}
   }
   for(c=0;c<time;c++)
    {
     a=y[c];
     lcm=lcm/gcd(lcm,a)*a;
    }
    printf("%d\n",lcm%1000000000);
  }  
 return 0;
}

我先切割數字,存到陣列,在提陣列的值出來做最小公倍數

#1207: Re:要怎麼加速 不逾時


magrady (元元)


for(c=0;c<=strlen(x);c++) 


strlen別放在終止條件,神說這樣不好......
#1208: Re:要怎麼加速 不逾時


magrady (元元)


for(c=0;c<=strlen(x);c++) 


strlen別放在終止條件,神說這樣不好......

有時候問問神吧,很靈驗的
#1211: Re:要怎麼加速 不逾時


morris1028 (碼畜)


for(c=0;c<=strlen(x);c++) 


strlen別放在終止條件,神說這樣不好......

有時候問問神吧,很靈驗的


真的耶,非常感謝您。雖然還是在WA
#1213: Re:要怎麼加速 不逾時


magrady (元元)


for(c=0;c<=strlen(x);c++) 


strlen別放在終止條件,神說這樣不好......

有時候問問神吧,很靈驗的


真的耶,非常感謝您。雖然還是在WA


Google 大神很有用

 1002通常是long long