Editorial for Secret Primary Factor
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
# Take input as a string instead of a number
N = input()
# Take the absolute of (Odd and Even)'s subtraction
delta = abs( int(N[0::2]) - int(N[1::2]) )
# Primary number filtering
is_primary = [True]*100
for i in range(2, 100):
if(not is_primary[i]): continue
# if i is a primary number, than all multiplication of i is !not! a primary number
is_primary[i*2:100:i] = [False]*int((100-i*2)/i + ((100-i*2)%i != 0)) # [False]*len(range(i*2, 100, i))
# prime factorization
while(delta%i == 0):
delta //= i
# if completely factorized, current prim is the largest primary factor
if(delta == 1):
print(i)
break
Comments