fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. inline bool is_palindrome(uint64_t n, uint64_t k)
  8. {
  9. if (n < 10 && k < 10)
  10. return true;
  11. int first_digit = n / k;
  12. int last_digit = n % 10;
  13. if (first_digit == last_digit)
  14. return is_palindrome((n % k) / 10, k / 100);
  15. else
  16. return false;
  17. }
  18.  
  19. inline uint64_t get_divider(uint64_t n)
  20. {
  21. uint64_t divider = 1;
  22. while (n / divider >= 10){
  23. divider *= 10;
  24. }
  25.  
  26. return divider;
  27. }
  28.  
  29. int main() {
  30. int length = 3;
  31. int max = std::pow(10, length) - 1;
  32. int min = std::pow(10, length - 1) - 1;
  33.  
  34. //cout << max << ":" << min;
  35.  
  36. uint64_t max_palindrome = 0;
  37. uint64_t n1, n2 = max;
  38. for (uint64_t i = max; i > min; i--)
  39. {
  40. for (uint64_t j = max; j >= min; j--)
  41. {
  42. //cout << i << "*" << j << endl;
  43. uint64_t number = i * j;
  44. if (is_palindrome(number, get_divider(number)))
  45. {
  46. if (number > max_palindrome)
  47. {
  48. max_palindrome = number;
  49. n1 = i;
  50. n2 = j;
  51. cout << n1 << "*" << n2 << "=" << max_palindrome <<endl;
  52. }
  53. }
  54. }
  55. }
  56. cout << n1 << "*" << n2 << "=" << max_palindrome <<endl;
  57. return 0;
  58. }
Success #stdin #stdout 0.12s 3456KB
stdin
Standard input is empty
stdout
995*583=580085
993*913=906609
993*913=906609