BC162 牛牛的素数判断

思路:

step1:素数判断,注意这里可以减小复杂度;

代码如下:

m = int(input())
def fn(n):
    flag = True
    i = 2
    while i <= n**0.5 + 1:
        if n%i == 0 and n != 2:
            flag = False
        i += 1
    if flag:
        print('true')
    else:
        print('false')
while True:
    try:
        n = int(input())
        fn(n)
    except:
        break