#6017: C語言~狂TLE((想破頭了QQ請各位大大幫忙


jay0935199 (黑羽)


請各位大大幫忙~

#include<stdio.h>
main()
{
int a,b,c;
int d = 0;
   
while(scanf("%d",&a)!=EOF)
{
 if(a>=2 && a<=2147483647)
   {
   for(b=1;b<=a;b++)
      {
      c = a%b;
      if(c==0)
      d = d+1;            
      }
   if(d>2)
   printf("\n非質數\n\n");
   else
   printf("\n質數\n\n");
   
   d = 0;
   }
}
return 0;                  
}

 

顯示如下

 

TLE (1s)
執行逾時

Killed 

 

#6019: Re:C語言~狂TLE((想破頭了QQ請各位大大幫忙


sponge (qd)


請各位大大幫忙~

#include
main()
{
int a,b,c;
int d = 0;
   
while(scanf("%d",&a)!=EOF)
{
 if(a>=2 && a<=2147483647)
   {
   for(b=1;b<=a;b++)
      {
      c = a%b;
      if(c==0)
      d = d+1;            
      }
   if(d>2)
   printf("\n非質數\n\n");
   else
   printf("\n質數\n\n");
   
   d = 0;
   }
}
return 0;                  
}

 

顯示如下

 

TLE (1s)
執行逾時

Killed 

 

c=0 就該跳出了。
#6020: Re:C語言~狂TLE((想破頭了QQ請各位大大幫忙


ianlo_511 (J.羅)


請各位大大幫忙~

#include
main()
{
int a,b,c;
int d = 0;
   
while(scanf("%d",&a)!=EOF)
{
 if(a>=2 && a<=2147483647)
   {
   for(b=1;b<=a;b++)
      {
      c = a%b;
      if(c==0)
      d = d+1;            
      }
   if(d>2)
   printf("\n非質數\n\n");
   else
   printf("\n質數\n\n");
   
   d = 0;
   }
}
return 0;                  
}

 

顯示如下

 

TLE (1s)
執行逾時

Killed 

 沒break掉會跑到天荒地老喔

 


#6073: Re:C語言~狂TLE((想破頭了QQ請各位大大幫忙


jay0935199 (黑羽)


請各位大大幫忙~

#include
main()
{
int a,b,c;
int d = 0;
   
while(scanf("%d",&a)!=EOF)
{
 if(a>=2 && a<=2147483647)
   {
   for(b=1;b<=a;b++)
      {
      c = a%b;
      if(c==0)
      d = d+1;            
      }
   if(d>2)
   printf("\n非質數\n\n");
   else
   printf("\n質數\n\n");
   
   d = 0;
   }
}
return 0;                  
}

 

顯示如下

 

TLE (1s)
執行逾時

Killed 

 沒break掉會跑到天荒地老喔

 

萬分感謝~

#6074: Re:C語言~狂TLE((想破頭了QQ請各位大大幫忙


jay0935199 (黑羽)


請各位大大幫忙~

#include
main()
{
int a,b,c;
int d = 0;
   
while(scanf("%d",&a)!=EOF)
{
 if(a>=2 && a<=2147483647)
   {
   for(b=1;b<=a;b++)
      {
      c = a%b;
      if(c==0)
      d = d+1;            
      }
   if(d>2)
   printf("\n非質數\n\n");
   else
   printf("\n質數\n\n");
   
   d = 0;
   }
}
return 0;                  
}

 

顯示如下

 

TLE (1s)
執行逾時

Killed 

 

c=0 就該跳出了。

萬分感謝~