How do I find factors of large numbers?

I have to find the factors of 900851475143........
In which data type do i store it?
Also if I use double, I cant use % operator to get its factors!
HELP appreciated
If you cannot use % operator than make a function of your own and use it.
You do not use a double to get the factors of this number, just an integer. There is no reason to use a double here. Your compiler might support integers this big. Try:
 
unsigned long int a = 900851475143;

or
 
unsigned long long int a = 900851475143;

If this does not work, then you are stuck with 32 bits, but you can use:

https://mattmccutchen.net/bigint/

or

http://gmplib.org/

An unrelated tip: If you estimate the square root of the number first, you can stop the program when it reaches the square root. This will save lots of time calculating the factors. Calculating factors of very large integers can take a long time.
Last edited on
I think that for your number long as implemented in most cases won't do. Usually max number is 4,294,967,295 (not enough).

On the other hand unsigned long long if supported is enough.

In VS c++ max num is 18,446,744,073,709,551,615
thanks mats and eypros too!
Topic archived. No new replies allowed.