Skip to content

Instantly share code, notes, and snippets.

@qlkzy
Last active December 29, 2015 09:18
Show Gist options
  • Select an option

  • Save qlkzy/7648940 to your computer and use it in GitHub Desktop.

Select an option

Save qlkzy/7648940 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
static int palindromic(uint64_t x)
{
uint64_t rev = 0;
for (uint64_t tmp = x; tmp; tmp /= 10) {
rev *= 10;
rev += tmp % 10;
}
return x == rev;
}
int main()
{
uint64_t max = 0;
uint64_t f_a, f_b, f_c, f_d;
for (uint64_t r = 10000; r > 0; --r)
for (uint64_t a = 99; a > 10; --a)
for (uint64_t b = a; b > 10; --b)
for (uint64_t c = b; c > 10; --c)
for (uint64_t d = c; d > 10; --d) {
uint64_t curr = a*b*c*d;
if (curr < max) break;
if (!palindromic(curr)) continue;
max = curr;
f_a = a;
f_b = b;
f_c = c;
f_d = d;
}
printf("%lu * %lu * %lu * %lu = %lu\n", f_a, f_b, f_c, f_d, max);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment