Problems > Factor the Giant

Factor the Giant

Difficulty: 2300 6000 ms 128 MB

number-theory pollard-rho

Print the prime factorization of N (up to 1018) in increasing prime order, formatted like 2^3 7 13^2 (exponent 1 omitted).

Input: one integer N.

Output: the factorization, or 1 when N = 1.

Constraints:

  • 1 ≤ N ≤ 1018

Sample Tests

Input 1
360
Output 1
2^3 3^2 5
Input 2
1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.