-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_Largest_palindrome_product.cpp
80 lines (60 loc) · 2.87 KB
/
4_Largest_palindrome_product.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
// bool ispalindrome(long long int s)
// {
// char nums[12];
// int i,j;
// for(i=0;s>0;i++)
// {
// nums[i]=s%10;
// s=s/10;
// }
// i--;
// for(j=0;j<i;j++,i--)
// {
// if(nums[i]!=nums[j])
// return false;
// }
// return true;
// }
// bool ismultiple(long long int s)
// {
// long long int i,j;
// for(i=101;i<1000;i++)
// for(j=101;j<1000;j++)
// {
// if(i*j==s)
// return true;
// }
// return false;
// }
int main() {
// long long int s=101101,e=1000000;
// for(;s<e;s++)
// {
// if(ispalindrome(s))
// {
// if(ismultiple(s))
// cout<<s<<",";
// }
// }
long long int sourceArray[]= {101101,102201,105501,106601,108801,110011,111111,117711,119911,121121,122221,123321,127721,128821,129921,131131,133331,135531,137731,138831,140041,141141,142241,143341,147741,149941,154451,155551,156651,159951,161161,162261,165561,168861,171171,174471,178871,180081,182281,184481,187781,188881,189981,198891,201102,202202,204402,209902,210012,212212,213312,214412,215512,216612,219912,220022,221122,222222,225522,227722,231132,232232,234432,235532,238832,239932,242242,244442,246642,249942,252252,255552,256652,257752,258852,259952,262262,266662,270072,272272,273372,276672,277772,279972,280082,282282,284482,286682,289982,290092,292292,294492,296692,297792,299992,301103,302203,303303,306603,308803,320023,321123,324423,329923,330033,333333,335533,343343,345543,348843,354453,357753,359953,363363,366663,367763,369963,371173,372273,374473,375573,377773,378873,384483,391193,393393,397793,399993,401104,402204,404404,405504,407704,408804,409904,412214,414414,416614,420024,421124,424424,425524,426624,428824,432234,434434,436634,438834,440044,441144,442244,443344,444444,445544,447744,452254,456654,459954,461164,462264,464464,468864,469964,470074,471174,474474,476674,477774,484484,485584,487784,488884,489984,491194,493394,505505,506605,507705,508805,509905,510015,512215,513315,514415,515515,519915,520025,522225,523325,525525,528825,531135,534435,535535,536635,543345,545545,548845,549945,550055,551155,554455,555555,560065,561165,564465,565565,570075,571175,573375,575575,576675,577775,579975,580085,585585,588885,589985,592295,595595,601106,602206,603306,604406,606606,611116,612216,616616,618816,619916,623326,630036,631136,636636,639936,642246,648846,649946,650056,652256,653356,654456,656656,657756,660066,661166,663366,666666,672276,675576,678876,689986,693396,696696,698896,723327,729927,737737,747747,749947,770077,780087,793397,801108,802208,804408,807708,809908,819918,821128,824428,828828,840048,853358,855558,861168,886688,888888,906609};
int t,i;
cin>>t;
while(t--)
{
long long int n;
cin>>n;
for(i=0;;i++)
{
if(sourceArray[i]>=n)
break;
}
cout<<sourceArray[i-1]<<endl;
}
return 0;
}