CF BUDDY
← Problems·

1787B · Number Factorization

1100 · greedy, math, number theory

Problem: Given an integer nn.

Consider all pairs of integer arrays aa and pp of the same length such that n=aipin = \prod a_i^{p_i} (i.e. a1p1a2p2a_1^{p_1}\cdot a_2^{p_2}\cdot\ldots) (ai>1;pi>0a_i>1;p_i>0) and aia_i is the product of some (possibly one) distinct prime numbers.

For example, for n=28=2271=4171n = 28 = 2^2\cdot 7^1 = 4^1 \cdot 7^1 the array pair a=[2,7]a = [2, 7], p=[2,1]p = [2, 1] is correct, but the pair of arrays a=[4,7]a = [4, 7], p=[1,1]p = [1, 1] is not, because 4=224=2^2 is a product of non-distinct prime numbers.

Your task is to find the maximum value of aipi\sum a_i \cdot p_i (i.e. a1p1+a2p2+a_1\cdot p_1 + a_2\cdot p_2 + \ldots) over all possible pairs of arrays aa and pp. Note that you do not need to minimize or maximize the length of the arrays.

Input Format: Each test contains multiple test cases. The first line contains an integer tt (1t10001 \le t \le 1000) — the number of test cases.

Each test case contains only one integer nn (2n1092 \le n \le 10^9).

Output Format: For each test case, print the maximum value of aipi\sum a_i \cdot p_i.

Note: In the first test case, 100=102100 = 10^2 so that a=[10]a = [10], p=[2]p = [2] when aipi\sum a_i \cdot p_i hits the maximum value 102=2010\cdot 2 = 20. Also, a=[100]a = [100], p=[1]p = [1] does not work since 100100 is not made of distinct prime factors.

In the second test case, we can consider 1010 as 10110^1, so a=[10]a = [10], p=[1]p = [1]. Notice that when 10=215110 = 2^1\cdot 5^1, aipi=7\sum a_i \cdot p_i = 7.

Sample Cases

Case 1

Input

7
100
10
864
130056192
1000000000
2
999999018

Output

20
10
22
118
90
2
333333009

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback