Date created: 07/10/11 19:27:04. Last modified: 08/06/16 22:10:48

Problem 16

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

int main (int argc, char *argv[]) {
        //This was the code used to generate the power
	//char power[310];
	//sprintf(power, "%20.f", pow(2,1000));
	//printf("2^1000 %s\n", power);
	
	string power = "10715086071862673209484250490600018105614"\
			"04811705533607443750388370351051124936122"\
			"493198378815695858127594672917553146825187"\
			"14528569231404359845775746985748039345677748"\
			"242309854210746050623711418779541821530464749"\
			"835819412673987675591655439460770629145711964"\
			"77686542167660429831652624386837205668069376";
	int i;
	long total = 0;
	for(i=0;i<303;i++) {
		total = total + atoi(power.substr(i,1).c_str());	
	}

	printf("total: %ld\n", total);
	return EXIT_SUCCESS;
}

Previous page: Problem 14
Next page: Problem 20