Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- # The script calculates maximum prime divisor of a positive integer.
- # Apart from input and output instructions the code's purely
- # functional (as far as I can judge). The script may exceed the
- # maximum recursion depth or make the interpreter freeze.
- def divisorGenerator(a, b):
- return divisibilityCheck(a, a // (a // b + 1))
- def divisibilityCheck(a, b):
- if a % b == 0:
- return primeCheck(a, b)
- else:
- return limitCheck(a, b)
- def limitCheck(a, b):
- if b > 1:
- return divisorGenerator(a, b)
- else:
- return b
- def primeCheck(a, b):
- if not [c for c in range(2, b // 2 + 1) if b % c == 0]:
- return b
- else:
- return limitCheck(a, b)
- def intializer(a):
- return limitCheck(a, a // 2)
- a = None
- while not a:
- a = input("Enter a positive decimal integer to start evaluation or a non-number to exit: ")
- if a.isnumeric():
- try:
- print(intializer(int(a)))
- except:
- print("Ouch! This one didn't go down well!")
- a = None
- else:
- exit("Oh, well...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement