FACT0 - Integer Factorization (15 digits)


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

hide comments
lm10_piyush: 2019-11-21 16:37:12

I have tried sieve with prime integer factorization but it gives me WA, anyone suggests any issue, I've test my code on many test cases it works fine.. largest number is 999999999999999 (9 15times).

Last edit: 2019-11-21 16:41:57
zarif_2002: 2019-11-02 09:04:02

Just do basic sieve before approaching. that's it.

drdrunkenstein: 2019-08-23 20:42:08

Python 3 gets tle for trial division

scolar_fuad: 2019-07-02 14:01:17

Easy just use primefactorization of number

karan_yadav: 2018-07-07 10:48:37

WTF!!!
Brute force works!!!
Guess no. of test cases is low

zephyr_96: 2018-05-19 09:47:49

Precal using sieve will give TLE. Normal O(root(n)) works. :|

ameyanator: 2018-04-01 22:16:52

Well if you know how to calculate the number of divisors of a number in sqrt(N) time then this is a easy question I guess

jayharsh: 2017-08-15 16:06:15

you will get TLE in brute force but optimize it and your code will work

raichu7: 2017-07-27 00:28:37

TLE-->AC :)

abudraya: 2017-07-23 21:04:04

nice one problem


Added by:Jimmy
Date:2009-10-08
Time limit:1.138s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL NODEJS PERL6 VB.NET