Last active
August 26, 2020 19:20
-
-
Save abecus/142d781a278c8aec32b17daa95596eff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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