QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561875#9248. An Easy Math Problemucup-team1766RE 0ms0kbPython31.6kb2024-09-13 11:53:522024-09-13 11:53:52

Judging History

This is the latest submission verdict.

  • [2024-10-31 22:36:43]
  • hack成功,自动添加数据
  • (/hack/1098)
  • [2024-10-31 22:13:58]
  • hack成功,自动添加数据
  • (/hack/1096)
  • [2024-10-31 22:00:43]
  • hack成功,自动添加数据
  • (/hack/1095)
  • [2024-09-13 11:53:52]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-09-13 11:53:52]
  • Submitted

answer

import sys
import threading
import math

def main():
    import sys

    # Increase the recursion limit to handle deep recursions if necessary
    sys.setrecursionlimit(1 << 25)

    # Sieve of Eratosthenes to generate primes up to 1e5
    def sieve(n):
        sieve = [True] * (n + 1)
        sieve[0] = sieve[1] = False
        for i in range(2, int(n**0.5) + 1):
            if sieve[i]:
                for j in range(i*i, n + 1, i):
                    sieve[j] = False
        primes = [i for i, is_prime in enumerate(sieve) if is_prime]
        return primes

    primes = sieve(100000)  # Precompute primes up to 1e5

    # Function to factorize a number using the precomputed primes
    def factorize(n):
        factors = {}
        for p in primes:
            if p * p > n:
                break
            while n % p == 0:
                factors[p] = factors.get(p, 0) + 1
                n //= p
        if n > 1:
            factors[n] = factors.get(n, 0) + 1
        return factors

    # Read all input at once for efficiency
    input = sys.stdin.read().split()
    q = int(input[0])
    for i in range(1, q + 1):
        n = int(input[i])
        if n == 0:
            print(0)
            continue
        factors = factorize(n)
        total = 1
        for e in factors.values():
            total *= (2 * e + 1)
        answer = (total + 1) // 2
        print(answer)

# Run the main function in a separate thread to handle large inputs efficiently
if __name__ == "__main__":
    threading.Thread(target=main).start()

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

10
1
2
3
4
5
6
7
8
9
10

output:


result: