-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp63.cpp
More file actions
45 lines (42 loc) · 1006 Bytes
/
Copy pathp63.cpp
File metadata and controls
45 lines (42 loc) · 1006 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* The 5-digit number, 16807=7^5, is also a fifth power. Similarly, the
* 9-digit number, 134217728=8^9, is a ninth power.
*
* How many k-digit positive integers exist which are also an kth power?
*
* SOLUTION:
*
* Let n be a k-digit positive integer that is a kth power of integer d. Then
*
* 10^(k-1) <= n = d^k < 10^k
*
* which leads to 1 <= d <= 9 and
*
* 1
* 1 <= k <= -----------
* 1 - lg(d)
*
* where lg denotes base-10 logarithm.
*
* ANSWER: 49
*/
#include <iostream>
#include <cmath>
#include "euler.h"
BEGIN_PROBLEM(63, solve_problem_63)
PROBLEM_TITLE("Powerful digit counts")
PROBLEM_ANSWER("49")
PROBLEM_DIFFICULTY(1)
PROBLEM_FUN_LEVEL(1)
PROBLEM_TIME_COMPLEXITY("")
PROBLEM_SPACE_COMPLEXITY("")
END_PROBLEM()
static void solve_problem_63()
{
int count = 0;
for (int d = 1; d <= 9; d++)
{
count += static_cast<int>(1.0 / (1.0 - std::log10(d)));
}
std::cout << count << std::endl;
}