How to create the most compact mapping n → isprime(n) up to a limit N?

后端 未结 30 2759
遇见更好的自我
遇见更好的自我 2020-11-22 02:11

Naturally, for bool isprime(number) there would be a data structure I could query.
I define the best algorithm, to be the algorithm that pr

30条回答
  •  失恋的感觉
    2020-11-22 02:51

    myInp=int(input("Enter a number: "))
    if myInp==1:
        print("The number {} is neither a prime not composite no".format(myInp))
    elif myInp>1:
        for i in range(2,myInp//2+1):
            if myInp%i==0:
                print("The Number {} is not a prime no".format(myInp))
                print("Because",i,"times",myInp//i,"is",myInp)
                break
        else:
            print("The Number {} is a prime no".format(myInp))
    else:
        print("Alas the no {} is a not a prime no".format(myInp))
    

提交回复
热议问题