#SP0000083. Phân tích thừa số nguyên tố (#04 – Prime Factorization)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân tích thừa số nguyên tố (#04 – Prime Factorization)
Prime Factorization (#04)
Source: LQDOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Every integer has a factorization into prime numbers. The prime factors must be written in increasing order. If a prime appears times, write it as ; if it occurs exactly once, write only .
Given an integer , output its prime factorization using the character * between factors and the character ^ before an exponent. Do not print spaces in the expression.
For instance, is written 3^2*5, while is written 2^4.
Input
A single line containing the integer to factorize.
Output
Print one line containing the prime factorization of . Prime bases must be in increasing order; include ^k only if ; join factors with * and print no spaces.
Subtasks
- Subtask 1 (60 points): .
- Subtask 2 (40 points): .
Examples
Example 1
Input
95256
Output
2^3*3^5*7^2
Explanation
Starting with , divide by three times to obtain , , and , so the exponent of is . Next, divide by five times, obtaining , , , , and . Finally, . Hence . The prime bases are in increasing order, so the answer is 2^3*3^5*7^2.
Example 2
Input
45
Output
3^2*5
Explanation
We have . Since appears twice, write 3^2. Since appears once, write 5 without an exponent. Joining these two factors with * gives 3^2*5.