PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000083. Phân tích thừa số nguyên tố (#04 – Prime Factorization)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 n≥2n\ge 2 has a factorization into prime numbers. The prime factors must be written in increasing order. If a prime pp appears k>1k>1 times, write it as pkp^k; if it occurs exactly once, write only pp.

Given an integer nn, output its prime factorization using the character * between factors and the character ^ before an exponent. Do not print spaces in the expression.

For instance, 45=32⋅545=3^2\cdot5 is written 3^2*5, while 16=2416=2^4 is written 2^4.

Input

A single line containing the integer nn to factorize.

Output

Print one line containing the prime factorization of nn. Prime bases must be in increasing order; include ^k only if k>1k>1; join factors with * and print no spaces.

Subtasks

  • Subtask 1 (60 points): 2≤n≤1032\le n\le 10^3.
  • Subtask 2 (40 points): 2≤n≤1072\le n\le 10^7.

Examples

Example 1

Input

95256

Output

2^3*3^5*7^2

Explanation

Starting with 9525695256, divide by 22 three times to obtain 4762847628, 2381423814, and 1190711907, so the exponent of 22 is 33. Next, divide 1190711907 by 33 five times, obtaining 39693969, 13231323, 441441, 147147, and 4949. Finally, 49=7⋅749=7\cdot7. Hence 95256=23⋅35⋅7295256=2^3\cdot3^5\cdot7^2. The prime bases 2,3,72,3,7 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 45=3⋅15=3⋅3⋅545=3\cdot15=3\cdot3\cdot5. Since 33 appears twice, write 3^2. Since 55 appears once, write 5 without an exponent. Joining these two factors with * gives 3^2*5.