close
Content

国王遇到了一个大问题。他与宰相比赛,看看谁判断质数判断得最快。国王知道宰相把671064内的质数都背下来了,所以国王想要你编一个程序,判断671064内的数是不是质数。

Input

有多组测试数据,读至EOF结束。数据的组数不会超过10000。每行1个测试数据。测试数据的范围0≤测试数据≤671064。

 

Output

对于每个测试数据,判断其是不是质数,如果是,请输出“It's a prime!!!”,否则,请输出“It's not a prime!!!”。

Sample Input #1
0
1
2
3
Sample Output #1
It's not a prime!!!
It's not a prime!!!
It's a prime!!!
It's a prime!!!

python:

max=671064
f=[0,1]*(max//2+1)
f[0]=0;f[1]=0;f[2]=1;f[3]=1
h=int(max**0.5)
for i in range(3,h+1,2):
    if(f[i]==1):
        for j in range(i*i,max+1,i*2):
            f[j]=0
w=[]
e=["It's not a prime!!!","It's a prime!!!"]
from sys import stdin
for s in stdin:
    ss=f[int(s)]
    if(ss==1):
        print("It's a prime!!!")
    else:
        print("It's not a prime!!!")
arrow
arrow
    文章標籤
    python 高中生程式解題
    全站熱搜
    創作者介紹
    創作者 趴趴熊日常 的頭像
    趴趴熊日常

    資工趴趴熊的小天地

    趴趴熊日常 發表在 痞客邦 留言(0) 人氣()