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

后端 未结 30 2740
遇见更好的自我
遇见更好的自我 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:54

    To find if the number or numbers in a range is/are prime.

    #!usr/bin/python3
    
    def prime_check(*args):
        for arg in args:
            if arg > 1:     # prime numbers are greater than 1
                for i in range(2,arg):   # check for factors
                    if(arg % i) == 0:
                        print(arg,"is not Prime")
                        print(i,"times",arg//i,"is",arg)
                        break
                else:
                    print(arg,"is Prime")
                    
                # if input number is less than
                # or equal to 1, it is not prime
            else:
                print(arg,"is not Prime")
        return
        
    # Calling Now
    prime_check(*list(range(101)))  # This will check all the numbers in range 0 to 100 
    prime_check(#anynumber)         # Put any number while calling it will check.
    

提交回复
热议问题