-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheuler016.cpp
More file actions
executable file
·31 lines (26 loc) · 812 Bytes
/
euler016.cpp
File metadata and controls
executable file
·31 lines (26 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*******************************************************************************
* Euler 16
* Power digit sum
* Author: Eugene Kolo - 2014
* Contact: www.eugenekolo.com
*
* 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
* What is the sum of the digits of the number 21000?
*******************************************************************************/
#include <iostream>
#include "InfInt.h"
// Makes use of the InfInt.h library found at http://code.google.com/p/infint/source/browse/trunk/InfInt.h?r=8
int main() {
InfInt num = 1;
// Calculate 2^1000
for (int i = 1; i <= 1000; i++) {
num = num*2;
}
// Add the digits
int sum = 0;
for (int i = 0; i <= num.numberOfDigits()-1; i++) {
sum = sum + num.digitAt(i);
}
std::cout << sum << std::endl;
return 0;
}