Sphere Online Judge

SPOJ Problem Set (classical)

4942. Integer Factorization (15 digits)

Problem code: FACT0

This is a problem to test the robustness of your Integer Factorization algorithm.

Given some integers, you need to factor them into product of prime numbers.

The largest integer given in the input file has 15 digits. FACT1 is a harder version of this problem (the numbers are larger).

You may need to use a general factorization algorithm since no special numbers (e.g. Fermat numbers) are considered when designing the input data.

Input

There are several numbers given, each one in a line.

The input ends with a number 0.

The number of test cases is about 10.

Output

For each number, print in a line the factorization of it. See examples below for the output format.

Example

Input:
3111989
13091989
77145199750673
0

Output:
317^1 9817^1
17^2 89^1 509^1
328439^1 234884407^1

Added by:Ngô Minh Ðức
Date:2009-10-08
Time limit:5s
Source limit:50000B
Languages:All except: ERL TECS

hide comments
2009-10-08 16:17:25 Ngô Minh Ðức
I'm sorry there was a bug in the test data. I've rejudged the submissions
2009-10-08 16:17:25 Luka Kalinovcic
I'm getting WA and I'm pretty sure the algorithm is correct. Please check the test data. Thanks
SPOJ System © 2008-2010 Sphere Research Labs. All Rights Reserved.