Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 25 October 2012 - 10:12 AM
Deltron Zero and Automator.
Posted 25 October 2012 - 10:59 AM
Posted 25 October 2012 - 11:03 AM
Edited by Olof Hedman, 25 October 2012 - 11:08 AM.
Posted 25 October 2012 - 11:11 AM
Posted 25 October 2012 - 11:42 AM
Deltron Zero and Automator.
Posted 25 October 2012 - 11:55 AM
Posted 25 October 2012 - 12:07 PM
long largest_prime_factor(long n) { // Take out all the factors of 2 while (n%2==0) n/=2; if (n==1) return 2; // Take out all the factors of 3 while (n%3==0) n/=3; if (n==1) return 3; for (long p=5; p*p<=n; p+=6) { // Take out all the factors of p while (n%p==0) n/=p; if (n==1) return p; long q = p+2; // Take out all the factors of q while (n%q==0) n/=q; if (n==1) return q; } return n; // If there's something left that doesn't have a divisor <= sqrt(n), then n is prime and we can return it. }
Posted 25 October 2012 - 12:28 PM
Edited by aavci, 25 October 2012 - 12:32 PM.
Posted 25 October 2012 - 07:15 PM
The main algorithmic improvement here is diving only by numbers up to the square root of the number.
...code snippet...
int largestPrimeFactor = 2; for (int i=2; i<=n; ++i) { while (n % i == 0) { n/=i; largestPrimeFactor = i; } }
Posted 27 October 2012 - 08:28 PM
Posted 27 October 2012 - 08:49 PM
Edited by Bacterius, 27 October 2012 - 08:53 PM.
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.