-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp4.cpp
More file actions
37 lines (35 loc) · 730 Bytes
/
Copy pathp4.cpp
File metadata and controls
37 lines (35 loc) · 730 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
#include <iostream>
#include "euler/digits.hpp"
#include "euler.h"
BEGIN_PROBLEM(4, solve_problem_4)
PROBLEM_TITLE("Find the largest palindrome made from the product of two 3-digit numbers")
PROBLEM_ANSWER("906609")
PROBLEM_DIFFICULTY(1)
PROBLEM_FUN_LEVEL(1)
PROBLEM_TIME_COMPLEXITY("N^2 log(N)")
PROBLEM_SPACE_COMPLEXITY("log(N)")
END_PROBLEM()
static void solve_problem_4()
{
int max_n = 0;
for (int a = 999; a >= 100; a--)
{
if (a * a <= max_n)
{
break;
}
for (int b = a; b >= 100; b--)
{
int n = a * b;
if (n <= max_n)
{
break;
}
if (euler::is_palindromic(n))
{
max_n = n;
}
}
}
std::cout << max_n << std::endl;
}