Surya loves to play with primes. One day, he asked his friend don to print any number in…
- User
Surya loves to play with primes. One day, he asked his friend don to print any number in the form of multiple of prime factors. Help don in solving the problem. Input The first line will contain an integer t (1 ≤ t ≤ 10^6) denoting number of test case. For each test case, you will be given an integer n (2 ≤ n ≤ 10^6).
Output Print a string showing prime factors which should look like : 2^e1 * p2^e2 * .........* pk^ek where p1, p2, ...., pn are the prime factors and e1, e2, ....., en is the degree of corresponding prime factor.
Note: power of 2 should always be given. For a prime number , only 2^0 is printed.
SAMPLE INPUT 3 32 100 9085
SAMPLE OUTPUT 2^5 2^25^2 2^05^123^179^1
Assistant
import sys max_n = 10**6 # Precompute smallest prime factors spf = list(range(max_n + 1)) for i in range(2, int(max_n**0.5) + 1): if spf[i] == i: for j in range(i*i, max_n+1, i): if spf[j] == j: spf[j] = i # Read input input_data = sys.stdin.read().split() t = int(input_data[0]) cases = list(map(int, input_data[1:t+1])) # Process each case for n in cases: factors = {} temp = n while temp > 1: p = spf[temp] while temp % p == 0: factors[p] = factors.get(p, 0) + 1 temp //= p e2 = factors.get(2, 0) parts = [f"2^{e2}"] rest = sorted([p for p in factors if p != 2]) for p in rest: parts.append(f"{p}^{factors[p]}") print('*'.join(parts))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.