Read the checking program (44 lines of Python)
"""Check a proper divisor of the composite Fermat number F20 by modular exponentiation."""
import json
import re
import sys
MAX_HEX_DIGITS = 131072
MAX_BYTES = MAX_HEX_DIGITS + 1
INDEX = 20
def verify(data, index=INDEX):
token = data.strip()
# The smaller factor is at most 2**(2**(index-1)). The bound below
# excludes only that even endpoint, which cannot divide an odd number.
digits = ((1 << (index - 1)) + 3) // 4
if len(token) > digits or not re.fullmatch(rb"[0-9a-fA-F]+", token):
raise ValueError("Give one hexadecimal divisor within the digit limit.")
divisor = int(token, 16)
if divisor < 3 or divisor % 2 == 0:
raise ValueError("The divisor must be odd and greater than one.")
if pow(2, 1 << index, divisor) != divisor - 1:
raise ValueError("The submitted number does not divide this Fermat number.")
return 0
def main():
data = sys.stdin.buffer.read(MAX_BYTES + 1)
try:
if len(data) > MAX_BYTES:
raise ValueError("The submission exceeds the byte limit.")
if not data.isascii() or any(c < 32 and c not in (9, 10, 13) for c in data):
raise ValueError("Use plain ASCII text.")
score = verify(data)
except ValueError as error:
result = {"valid": False, "score": None, "message": str(error)}
else:
result = {"valid": True, "score": score, "message": "The submitted divisor is a proper factor of the Fermat number."}
print(json.dumps(result))
if __name__ == "__main__":
main()