-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path004.cpp
More file actions
39 lines (33 loc) · 769 Bytes
/
004.cpp
File metadata and controls
39 lines (33 loc) · 769 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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int largestPalindrome(int n) {
// Definir as Restrições (Números de apenas três digitos)
int max = pow(10, n) - 1;
int min = 1 + max / 10;
// Iterar pelos dois números fazer os seus respectivos produtos
int ans = 0;
for (int i = max; i >= min; i--) {
for (int j = i; j >= min; j--) {
int p = i * j;
if (p < ans) {
break;
}
int n = p;
int reverse = 0;
while (n != 0) {
reverse = reverse * 10 + n % 10;
n /= 10;
}
if (p == reverse && p > ans) {
ans = p;
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << largestPalindrome(3) << "\n";
}