Problem: Given is a positive integer N. Consider repeatedly applying the operation below on N:    * First, choose a positive integer z satisfying all of the conditions below:     * z can be represented as z=p^e, where p is a prime number and e is a positive integer;     * z divides N;     * z is different from all integers chosen in previous operations.   * Then, replace N with N/z.  Find the maximum number of times the operation can be applied.

Submission attempts (in order):
import io,sys
sys.setrecursionlimit(10**6)

def prime(n):
    nums = [True]*n
    primes = []
    for i in range(2,n):
        if nums[i]:
            primes.append(i)
            for j in range(2*i,n,i):
                nums[j] = False
    return primes

def main():
    from collections import Counter
    from collections import deque
    import bisect
    n = int(input())
    num = Counter([])

    primes = prime(int(n**0.5+1))+[n]
    primes = deque(primes)

    while n !=1:
        while True:
            p = primes.popleft()
            q = primes.pop()
            if n%p==0:
                num[p]+=1
                n = n//p
                primes.appendleft(p)
                break
            elif n%q==0:
                num[q]+=1
                n = n//q
                primes.append(q)
                break

    m = max(num.values())
    N = [i*(i+1)//2 for i in range(1,int((2*m)**0.5)+1)]
    ans = 0
    for i in num.values():
        k = bisect.bisect_right(N,i)
        ans+=k
    print(ans)
main()

import io,sys
sys.setrecursionlimit(10**6)

def prime(n):
    nums = [True]*n
    primes = []
    for i in range(2,n):
        if nums[i]:
            primes.append(i)
            for j in range(2*i,n,i):
                nums[j] = False
    return primes

def main():
    from collections import Counter
    from collections import deque
    import bisect
    n = int(input())
    num = Counter([])

    primes = prime(int(n**0.5+1))+[n]
    primes = deque(primes)

    while n !=1:
        while len(primes)>0:
            p = primes.popleft()
            if len(primes)>0:
                q = primes.pop()
            else:
                q=10**10
            if n%p==0:
                num[p]+=1
                n = n//p
                primes.appendleft(p)
                break
            elif n%q==0:
                num[q]+=1
                n = n//q
                primes.append(q)
                break

    m = max(num.values())
    N = [i*(i+1)//2 for i in range(1,int((2*m)**0.5)+1)]
    ans = 0
    for i in num.values():
        k = bisect.bisect_right(N,i)
        ans+=k
    print(ans)
main()

def prime(n):
    nums = [True]*n
    primes = []
    for i in range(2,n):
        if nums[i]:
            primes.append(i)
            for j in range(2*i,n,i):
                nums[j] = False
    return primes

def prime_fac(n):
    fac = {}
    primes = prime(int(n**0.5)+1)
    for p in primes:
        while n%p==0:
            fac[p] = fac.get(p,0)+1
            n//=p
    if n > 1:
        fac[n] = 1
    return fac

def main():
    n = int(input())
    fac = prime_fac(n)

    ans = 0
    for i in fac.values():
        ct = 1
        while i >= ct*(ct+1)//2:
            ct += 1
            ans+=1
    print(ans)
main()

Verdicts: Runtime Error

Runtime Error

Accepted