#SP0000274. Phân tích thừa số nguyên tố (20 chữ số) (Integer Factorization (20 digits))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân tích thừa số nguyên tố (20 chữ số) (Integer Factorization (20 digits))
Integer Factorization (20 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
1000000000000000000
Output
2^18 5^18
Explanation
Observe $1000000000000000000=10^{18}=(2\cdot 5)^{18}=2^{18}\cdot 5^{18}$. 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^18 5^18.
Example 3
Input
10000000000000000000
Output
2^19 5^19
Explanation
Observe $10000000000000000000=10^{19}=(2\cdot 5)^{19}=2^{19}\cdot 5^{19}$. 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^19 5^19.