24h購物| | PChome| 登入
2009-04-04 13:55:16| 人氣423| 回應0 | 上一篇 | 下一篇

最小公倍數

推薦 0 收藏 0 轉貼0 訂閱站台

/***************************/

#include<stdio.h>                    
#include<stdlib.h>                 
#include<string.h>  
#include<math.h>  
char x[10000000];          
main()                 
{                 
 int a,b,c;  
 int math[5200]={0};              
 int m=1;     
 math[0]=2;  
 for(a=3;a<50000;a=a+2)/*5W*5W已經2.5E 無須建更大*/       
  {        
   int flag=0;        
   for(b=0;math[b]<=sqrt(a);b++)        
    {        
     if(a%math[b]==0)        
      {        
       flag=1;        
       break;        
      }        
    }        
    if(flag==0)        
     {        
      math[m]=a;        
      m++;        
     }        
  }  
 while(gets(x)!=0)                 
  {                 
   a=strlen(x);  
  if(x[0]=='0'&&strlen(x)==1) break;                 
  int temp1=0,max=0;  
  int ans[101]={0},top=0;  
  long long int ans2=1;  
  for(c=0;c<a;c++)     
   {                 
   if(x[c]<=57&&x[c]>=48)                 
    temp1=temp1*10+x[c]-48;                 
   else                  
    {           
     ans[top]=temp1;  
     top++;  
     if(temp1>=max)  
      max=temp1;   
     temp1=0;  
     }  
   }       
   ans[top]=temp1;  
   top++;  
   if(temp1>=max)  
      max=temp1;
   for(a=0;a<m&&math[a]<max;a++)  
     {  
      int flag=0;
     for(b=0;b<top;b++)  
        {   
        if(ans[b]%math[a]==0)  
         {   
          ans[b]/=math[a];  
          flag=1;   
         }  
        }   
       if(flag==1)  
        {  
         ans2*=math[a];  
         ans2%=100000000;   
         a--;   
        }   
     }
    for(a=0;a<top;a++)
     for(b=a+1;b<top;b++)
       if(ans[a]==ans[b])
        ans[b]=1;
    for(a=0;a<top;a++)  
     {   
      ans2*=ans[a];  
      ans2%=100000000;  
     }   
    printf("%lld\n",ans2);  
  }                    
 return 0;                 
}

台長: 來源不明

您可能對以下文章有興趣

人氣(423) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 數位資訊(科技、網路、通訊、家電) | 個人分類: ZeroJudge 基礎+原創題庫 |
此分類下一篇:好累的小玫
此分類上一篇:Stringstream運用練習(C++)

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文