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

#SP0000275. Phân tích thừa số nguyên tố (29 chữ số) (Integer Factorization (29 digits))

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ố (29 chữ số) (Integer Factorization (29 digits))

Integer Factorization (29 digits)

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given a positive integer NN, factor it into primes. For each distinct prime pp, let ee be its multiplicity in the factorization. Print every pep^e in ascending order of pp, including the exponent 11 when it occurs.

Input

One line contains the positive integer NN.

Output

Print one line of pairs p^e, one for each distinct prime factor pp with its exponent ee. Sort the pairs by increasing pp, separating adjacent pairs by one space. Always print the exponent, including ^1.

Subtasks

  • Subtask 1 (20 points): 2≤N≤10000002\le N\le 1000000. Time limit: 55 s.
  • Subtask 2 (30 points): 2≤N≤10000000000000000002\le N\le 1000000000000000000. Time limit: 1010 s.
  • Subtask 3 (50 points): 2≤N≤999999999999999999999999999992\le N\le 99999999999999999999999999999. Time limit: 1515 s.

Examples

Example 1

Input

60

Output

2^2 3^1 5^1

Explanation

Starting from 6060, divide successively by prime factors: 60÷2=3060\div 2=30; 30÷2=1530\div 2=15; 15÷3=515\div 3=5; 5÷5=15\div 5=1. Sort distinct prime factors in increasing order, writing each exponent including 11, 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 2020 copies of 22 and 2020 copies of 55. Sort distinct prime factors in increasing order, writing each exponent including 11, and separate the pairs by spaces. The output line is 2^20 5^20.

Example 3

Input

18446744073709551616

Output

2^64

Explanation

Starting from 18446744073709551616=26418446744073709551616=2^{64}, divide by 22 exactly 6464 times. The exponent decreases by one each time, reaching 11 after the last division. Sort distinct prime factors in increasing order, writing each exponent including 11, and separate the pairs by spaces. The output line is 2^64.