-4

i need to find factors of very big number say (10^1000) . i.e if input is 100 then output should be 10 10 because (10*10=100) .this is very simple if N<=size of (long) but i want to know how it will be possible to find factors of very big number say (10^1000). also i cant use Big Integer . .

Altaf Hussain
  • 25
  • 1
  • 1
  • 6
  • Might be worth asking this on http://math.stackexchange.com/ – Peter Sep 08 '14 at 13:49
  • 1
    This is a hard problem. See http://en.wikipedia.org/wiki/Integer_factorization. – lhf Sep 08 '14 at 13:51
  • Are you serious? This is only computable theoretically. Practically this can take decades. Many encryption algorithms (like AES) use this and would not be safe if you could compute quickly. – schubakah Sep 08 '14 at 14:08
  • Cross posted to http://math.stackexchange.com/questions/923724/how-to-find-factors-of-very-big-number. – lhf Sep 09 '14 at 13:27

2 Answers2

1

1) As has been pointed out, factoring large numbers is hard. It is in fact sufficiently hard that it's the basis for RSA public key cryptography, or in other words every time you buy something online, you are counting on the fact that it's hard to factor numbers of the order 2^2048 (given 2^10 = 1024 which is about 10^3, 2^2048 is about 10^600). While RSA specifically uses two large prime numbers and your random N may have lots of small numbers which will help somewhat, I wouldn't count on being able to factor 10^1000 +/- some random value anytime soon.

2) You can definitely reimplement big number library using strings [source: I had a classmate who did it before we learned about how to do big number math] but it's going to be painfully slow, and you basically have to cast your strings back to ints each time; a slightly less painful approach if you wanted to reimplmeent big numbers is arrays of integers. You still need to do some extra steps, but for doing at least basic math, it's not super difficult. (But it still won't be as efficient as specialized big number libraries, which can do clever algorithms. For example, multiplying 2 big numbers the straight forward way would be let A = P * 2^32 + Q (i.e. A is a 64 bit number represented as an array of 2 32 bit numbers) and B = R * 2^32 + S... the straightforward way takes 4 multiplactions plus some additions plus some dealing with carries). As the size of the big number increases, there are ways (see e.g. http://en.wikipedia.org/wiki/Karatsuba_algorithm) to reduce the number of multipication required)

3) (There are algorithms to more efficiently factor numbers compared to trial factorization, but the current ones are still not going to help compute the numbers you're asking about before the heat death of the universe)

Foon
  • 6,148
  • 11
  • 40
  • 42
-2

10^1000 has exactly 1,002,001 integer divisors, and they should be very easy to find with a bit of thinking. The prime factorisation is

2 * 2 * 2 * ... * 5 * 5 * 5

with exactly 1,000 twos and exactly 1,000 fives.

gnasher729
  • 51,477
  • 5
  • 75
  • 98