#6055: 這夠短ㄌ吧==但還是TLE~求解


alan7033 (焜為)


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

#6056: Re:這夠短ㄌ吧==但還是TLE~求解


sponge (qd)


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


又不是程式碼短,計算的時間就短。
#6058: Re:這夠短ㄌ吧==但還是TLE~求解


alan7033 (焜為)


  又不是程式碼短,計算的時間就短。
你沒回答到我"主要"的問題拉QQ
#6059: Re:這夠短ㄌ吧==但還是TLE~求解


sponge (qd)


  又不是程式碼短,計算的時間就短。
你沒回答到我"主要"的問題拉QQ


1)  a%b==0 就該脫出。

 

2) 不必讓 b 跑到 a

    跑到 a 的開根號就夠了

 

#6060: Re:這夠短ㄌ吧==但還是TLE~求解


alan7033 (焜為)



1)  a%b==0 就該脫出。
2) 不必讓 b 跑到 a
跑到 a 的開根號就夠了

 

萬分感謝^^~*