Skip to content

Instantly share code, notes, and snippets.

@abecus
Last active August 26, 2020 19:20
Show Gist options
  • Save abecus/142d781a278c8aec32b17daa95596eff to your computer and use it in GitHub Desktop.
Save abecus/142d781a278c8aec32b17daa95596eff to your computer and use it in GitHub Desktop.
def getReducedFactorization(N:int, spf:list)-> int:
"""
counts repetition of each prime from prime factorisation of N
using trial method upon spf list, and calculating the ceil of
half of all prime's powers (pow(p, ceil(a / 2))) and multiplying
them together.
"""
gamma = 1
while (N != 1):
# keep a prime in prev variable
prev = spf[N]
# for counting the power
c = 0
# counts power of a prime
while spf[N] == prev:
c += 1
N //= spf[N]
# multiplies the half ceil of power on primes
gamma *= pow(prev, ceil(c / 2))
prev = spf[N]
return gamma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment