Sphere Online Judge

SPOJ Problem Set (classical)

4941. Integer Factorization (20 digits)

Problem code: FACT1

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 20 digits. FACT2 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
2432902008176640000
77145199750673
0

Output:
317^1 9817^1
17^2 89^1 509^1
2^18 3^8 5^4 7^2 11^1 13^1 17^1 19^1
328439^1 234884407^1

Added by:Ngô Minh Ðức
Date:2009-10-08
Time limit:20s
Source limit:50000B
Languages:All except: CLOJ ERL F# PERL 6 TECS

hide comments
2010-08-29 09:24:53 changiz
BUT,java +BigInteger+ Brent Method=AC
2010-05-22 21:37:42 Lewin Gan
my tle algorithm for fact0 got ac for this one... very strange...

Last edit: 2010-05-23 05:16:55
2009-10-09 11:07:51 Zobayer
Can anyone suggest me an algorithm for this, my pollard rho got tle :"(
2009-10-08 16:20:38 Ngô Minh Ðức
(I've reduced the limit to 20 digits. Harder test case is now in problem FACT2.)


Last edit: 2009-10-08 16:20:01
2009-10-08 16:20:38 Q
> Ruslan Sennov :
> Python + Elliptic curves also got TLE :)

Judging on FACT0_4942, my code is almost by 2 times faster than yours, nonetheless on FACT1 I keep getting only TLEs
2009-10-08 16:20:38 Q
Thanks, Ngô Minh Ðức!

Last edit: 2009-10-08 10:18:19
2009-10-08 16:20:38 Ngô Minh Ðức
The error in your python code:
Traceback (most recent call last):
File "/sources/tested.py", line 39, in
File "/usr/lib/python2.6/random.py", line 48, in
from binascii import hexlify as _hexlify
ImportError: libz.so.1: cannot open shared object file: No such file or directory
2009-10-08 16:20:38 Q
I got the 2nd NZEC!
People, why these NZECs?
No empty lines in input, then what?


Last edit: 2009-10-08 09:39:04
2009-10-08 16:20:38 Ruslan Sennov
Python + Elliptic curves also got TLE :)
2009-10-08 16:20:38 Ngô Minh Ðức
There are inputs which are products of two large primes
SPOJ System © 2010 Sphere Research Labs. All Rights Reserved.