2013-04-17 14:34:39 +08:00

35 lines
722 B
C++

/** A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 * 99.
Find the largest palindrome made from the product of two 3-digit numbers.. */
/** 1001 = 7 * 11 * 13 */
#define _max 997
#include "0.hpp"
int main()
{
int pal = 0;
for(int i = _max; i >= 100; i--) {
int temp = i;
pal = 0;
while(temp > 0) {
pal = pal * 10 + temp % 10;
temp /= 10;
}
pal += i * 1000;
int m = 100;
do {
while(pal % m != 0) m++;
if(m < 1000 && pal / m < 1000) {
cout << pal << " = " << m << " * " << pal / m << endl;
return 0;
}
m++;
} while(m < 1000);
}
return 0;
}