Date created: Saturday, October 13, 2012 8:40:43 PM. Last modified: Thursday, December 13, 2012 11:41:20 AM

Problem 3

// ProjectEuler - Problem 3 - Revision 3, statically from the square root down

#include 
#include 
#include 

int main (int argc, char *argv[]) {

        long long int topend = 600851475143LLU;
        long squarert = 775147;
        long long int i = squarert;
        long long int j = (squarert - 1);
        
        printf("topend: %lld square: %ld\n", topend, squarert);

        while (i>1) {
                if (topend % i == 0) {
                        printf("%lld\n", i);
                        while (j>1) {
                                if (i % j != 0) {
                                        if (j == 2) {
                                                printf("%lld prime factor!\n", i);
                                                exit(0);
                                        }
                                        j--;
                                } else if (i % j == 0) {
                                        j = 0;
                                }
                        }
                }
                i--;
                j = (i - 1);
        }
        return EXIT_SUCCESS;

Previous page: Problem 2
Next page: Problem 4