Advertisement
makispaiktis

Problem 4 - x^2 + 1 = prime

Jul 5th, 2021 (edited)
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. # FUNCTION 1 - Finds if a number is prime
  2. def isPrime(n):
  3.     for i in range(2, int(n/2)):
  4.         if n % i == 0:
  5.             return False
  6.     return True
  7.  
  8.  
  9. # MAIN FUNCTION
  10. limit = 10**3
  11. for n in range(2, limit+1, 2):
  12.     flag = isPrime(n**2 + 1)
  13.     result = ""
  14.     if flag:
  15.         result = " is prime"
  16.     else:
  17.         result = " is not prime"
  18.     print("n = " + str(n) + " ----> n^2 + 1 = " + str(n**2+1) + result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement