Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Andrew Dahl
/
Project Euler
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0f004909
authored
Oct 16, 2012
by
Andrew Dahl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Solved Problem 30
parent
408ec9ba
Hide whitespace changes
Inline
Sidebyside
Showing
2 changed files
with
47 additions
and
0 deletions
30/README
30/main.cpp
30/README
0 → 100644
View file @
0f004909
Question:
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
1634 = 1^4 + 6^4 + 3^4 + 4^4
8208 = 8^4 + 2^4 + 0^4 + 8^4
9474 = 9^4 + 4^4 + 7^4 + 4^4
As 1 = 1^4 is not a sum it is not included.
The sum of these numbers is 1634 + 8208 + 9474 = 19316.
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
Answer:
443839
30/main.cpp
0 → 100644
View file @
0f004909
#include <iostream>
#include <sstream>
#include <string>
#include <math.h>
using
namespace
std
;
const
int
POW
=
5
;
const
int
MAX
=
10000000
;
int
main
()
{
stringstream
oss
;
string
str
=
""
;
int
tmp
=
0
;
int
sum
=
0
;
for
(
int
i
=
2
;
i
<
MAX
;
i
++
)
{
oss
<<
i
;
str
=
oss
.
str
();
tmp
=
0
;
for
(
int
j
=
0
;
j
<
str
.
length
();
j
++
)
{
tmp
+=
pow
(
str
[
j
]

48
,
POW
);
}
if
(
i
==
tmp
)
sum
+=
tmp
;
str
=
""
;
oss
.
str
(
string
()
);
oss
.
clear
();
}
cout
<<
sum
<<
endl
;
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment