zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Largest palindrome product

2023-03-14 10:17:16 时间

https://projecteuler.net/problem=4

1、它是回文数

2、存在2个三位数乘积等于它。

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 bool is_ok(int x)
 5 {
 6     if(x%10!=x/100000 || (x/10)%10!=(x/10000)%10 || (x/100)%10!=(x/1000)%10)
 7         return false;
 8     return true;
 9 }
10 bool is_ok1(int x)
11 {
12     for(int i=100;i<1000;i++)
13         for(int j=100;j<1000;j++)
14         if(i*j==x)
15         {
16     //    cout<<i<<"  "<<j<<endl;
17         return true;
18         }
19     return false;
20 }
21 int main()
22 {
23     for(int i=999999;i>=100000;i--)
24         if(is_ok(i) && is_ok1(i))
25         {
26              cout<<i<<endl;
27              break;
28         }
29     return 0;
30 }
View Code