Jul 13, 2010 at 1:02pm UTC
Please tell me the way to implement a c++ program to find the largest prime factor of a given number.
A hint would work.
Thank you
Jul 13, 2010 at 1:15pm UTC
Keep dividing the number by the smallest possible prime number until it is prime itself.
The result is the largest prime factor.
Jul 13, 2010 at 3:13pm UTC
But this may not be efficient method. Because I have to find the largest prime number of a very big number like 40000000
Jul 13, 2010 at 3:14pm UTC
Any method to find the prime number that could server the purpose here??????
Jul 13, 2010 at 3:21pm UTC
See Google "c++ integer factorization library", first hit.
Jul 14, 2010 at 2:01pm UTC
I am not able to understand the whatever is given in that link
Jul 15, 2010 at 3:31am UTC
But I want to manually write a program for this
Jul 15, 2010 at 2:55pm UTC
How to handle data as large as 600851475143??
Please suggest some solution
Jul 15, 2010 at 5:42pm UTC
Google "bignum library" or something similar.
Jul 15, 2010 at 5:54pm UTC
are you sure you want to do this?
once you have discovered how to do this in
reasonable time you will be a multi-millionaire!
but,
you will instantly nullify all cryptographic security, bring the world of e-commerce to it's knees, invoking a
financial crisis that will make the recent credit-crunch seem like a picnic.
widespread panic, the world stock markets will cease to function, countries will collapse
bringing the onset of war, famine, pestilence, the civilised world will plunge into a new dark age.
is that what you want?
Jul 16, 2010 at 2:37pm UTC
Heyy there must be some way to do this.
Please suggest some method
Jul 16, 2010 at 2:42pm UTC
You can start with using int64_t (or long long), that'll be big enough to hold 600851475143.
For larger numbers, you'll have to use GMP.
Jul 16, 2010 at 3:14pm UTC
Read obout Sieve of Eratosthenes.
Jul 18, 2010 at 5:52am UTC
I tried using int64_t but Semgentation Fault is coming
Jul 23, 2010 at 6:43am UTC
I tried to use long long on my devc++
But its range is coming out to be equal to that of int
I am using windows Vista home premium
Please sugest some solution
Jul 23, 2010 at 8:51am UTC
Find the smallest prime factor and divide the number by that. You'll reach a solution faster, i think
Last edited on Jul 23, 2010 at 8:53am UTC
Jul 23, 2010 at 12:58pm UTC
But my program is not running .
Segmentation error is coming
@line
1 2
long long int ="600851475143" ;
The range of long long is very very larger than this number but its not working
Please suggest some solution
Last edited on Jul 23, 2010 at 12:59pm UTC
Jul 23, 2010 at 1:02pm UTC
"600851475143"
is a string literal not a number. Try long long int number = 600851475143;
Last edited on Jul 23, 2010 at 1:02pm UTC