Date created: Sunday, July 10, 2011 7:24:16 PM. Last modified: Thursday, December 13, 2012 11:41:20 AM

Problem 10

// Project Euler - Problem 10
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;

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

	long i = 1;
	long j = 2;
	long topend = atoi(argv[1]);
	long long total = 2;

	while (i<topend) {
		while (j<i) {
			if (i % j != 0) {
				if (j == (i - 1)) {
					total = total + i;
				}
				j++;
			} else if (i % j == 0) {
				j = i;
			}
		}
		j=2;
		i++;
	}
	cout << total << "\n";
	return EXIT_SUCCESS;
}

Previous page: Problem 9
Next page: Problem 13