#SP0000275. Phân tích thừa số nguyên tố (29 chữ số) (Integer Factorization (29 digits))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân tích thừa số nguyên tố (29 chữ số) (Integer Factorization (29 digits))
Integer Factorization (29 digits)
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer , factor it into primes. For each distinct prime , let be its multiplicity in the factorization. Print every in ascending order of , including the exponent when it occurs.
Input
One line contains the positive integer .
Output
Print one line of pairs p^e, one for each distinct prime factor with its exponent . Sort the pairs by increasing , separating adjacent pairs by one space. Always print the exponent, including ^1.
Subtasks
- Subtask 1 (20 points): . Time limit: s.
- Subtask 2 (30 points): . Time limit: s.
- Subtask 3 (50 points): . Time limit: s.
Examples
Example 1
Input
60
Output
2^2 3^1 5^1
Explanation
Starting from , divide successively by prime factors: ; ; ; . Sort distinct prime factors in increasing order, writing each exponent including , and separate the pairs by spaces. The output line is 2^2 3^1 5^1.
Example 2
Input
100000000000000000000
Output
2^20 5^20
Explanation
Observe $100000000000000000000=10^{20}=(2\cdot 5)^{20}=2^{20}\cdot 5^{20}$. Therefore the factorization contains exactly copies of and copies of . Sort distinct prime factors in increasing order, writing each exponent including , and separate the pairs by spaces. The output line is 2^20 5^20.
Example 3
Input
18446744073709551616
Output
2^64
Explanation
Starting from , divide by exactly times. The exponent decreases by one each time, reaching after the last division. Sort distinct prime factors in increasing order, writing each exponent including , and separate the pairs by spaces. The output line is 2^64.