#6077: 我一直TLE想不出我哪裡有問題


ABC3286221 (博丞)


#include<iostream>

using namespace std;

int main()
{
int a,b;
bool c;

while(cin>>a){

if(a<=2){
c= true;}
else if(a%2==0){
c = false;}
else {
c = true;
for(b=3;3*3<=a;b=b+2){
if(a%b==0){
           c = false;
           break;
           }
           }
           }
 cout<<(c ? "  " : "非")<<"質數\n";
}
return 0;
}
           
#6083: Re:我一直TLE想不出我哪裡有問題


ABC3286221 (博丞)


#include<iostream>
using namespace std;
int main()
{
int a,b;
bool c;
while(cin>>a){
if(a>=2147483647){
break;}
                
if(a<=2){
 c= true;}
else if(a%2==0){
 c = false;}
else {
 c = true;
for(b=3;b*b<=a;b=b+2){
if(a%b==0){
           c = false;
           break;
           }
           }
           }
 cout<<(c ? "質數" : "非質數")<<'\n';
}
return 0;
}
           現在這是我目前更動的程式碼

我已經解決愈時問題 但是我現在是搞不懂 line:1 WA  目前輸出0

我有迴圈為甚麼還會這樣

 

#6084: Re:我一直TLE想不出我哪裡有問題


jimmyee (LEVEL_UP)


#include
using namespace std;
int main()
{
int a,b;
bool c;
while(cin>>a){
if(a>=2147483647){
break;}
                
if(a<=2){
 c= true;}
else if(a%2==0){
 c = false;}
else {
 c = true;
for(b=3;b*b<=a;b=b+2){
if(a%b==0){
           c = false;
           break;
           }
           }
           }
 cout<<(c ? "質數" : "非質數")<<'\n';
}
return 0;
}
           現在這是我目前更動的程式碼

我已經解決愈時問題 但是我現在是搞不懂 line:1 WA  目前輸出0

我有迴圈為甚麼還會這樣

 



#6085: Re:我一直TLE想不出我哪裡有問題


jimmyee (LEVEL_UP)


#include
using namespace std;
int main()
{
int a,b;
bool c;
while(cin>>a){
if(a>=2147483647){
break;}
                
if(a<=2){
 c= true;}
else if(a%2==0){
 c = false;}
else {
 c = true;
for(b=3;b*b<=a;b=b+2){
if(a%b==0){
           c = false;
           break;
           }
           }
           }
 cout<<(c ? "質數" : "非質數")<<'\n';
}
return 0;
}
           現在這是我目前更動的程式碼

我已經解決愈時問題 但是我現在是搞不懂 line:1 WA  目前輸出0

我有迴圈為甚麼還會這樣


被吃字了
1不是質數喔,而且2147483647是質數

#6092: Re:我一直TLE想不出我哪裡有問題


ABC3286221 (博丞)


不懂吃字是什麼意思

爾且我現在不知如何讓2147483674判斷為質數

麻煩你告訴我解決問題

或者可以幫我改程式碼 正確的