Project Euler problem 16
This commit is contained in:
@@ -1,30 +1,23 @@
|
||||
/* Check cf5-opt.vim defs.
|
||||
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
|
||||
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
|
||||
VIM: let g:argv=""
|
||||
VIM-: let g:cf5output=0
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#Power digit sum
|
||||
#Problem 16
|
||||
#
|
||||
#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?
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
int main ( void )
|
||||
{try{
|
||||
pp = 1000
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch ( const std::exception& e )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cerr << std::endl
|
||||
<< "unknown exception." << std::endl;
|
||||
return 1;
|
||||
}}
|
||||
c = [0 for i in range(0, pp//3+1)]
|
||||
c[0] = 1
|
||||
|
||||
for i in range(0,pp):
|
||||
r = 0
|
||||
for j in range(0,len(c)):
|
||||
p = c[j]*2+r
|
||||
r = p//10
|
||||
c[j] = p%10
|
||||
s = 0
|
||||
for i in c:
|
||||
s += i
|
||||
print( s )
|
||||
|
||||
Reference in New Issue
Block a user