Last active
March 10, 2017 09:41
-
-
Save creaktive/6a71a3f138510b23b6159656ece65692 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
int main() { | |
int w = 6; | |
int l = pow(10, w - 1); | |
int t = pow(10, w); | |
int h = t - 1; | |
for (long i = h; i > l; i--) { | |
long b = i; | |
long p = 0; | |
for (int j = 1; b > 0; j++) { | |
int e = pow(10, j); | |
int r = b % e; | |
p += pow(10, w - j) * (r / pow(10, j - 1)); | |
b -= r; | |
} | |
p = i * t + p; | |
for (int j = h; j > l; j--) { | |
if (p % j == 0 && p / j < t) { | |
std::cout << p << " = " << j << " * " << p / j << std::endl; | |
return 0; | |
} | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def euler004(w): | |
l = 10 ** (w - 1) | |
h = 10 ** w - 1 | |
t = 10 ** w | |
for i in xrange(h, l, -1): | |
s = str(i) | |
p = int(s + s[::-1]) | |
for j in xrange(h, l, -1): | |
if p % j == 0 and p / j < t: | |
return p, j, p / j | |
print "%d = %d * %d" % euler004(int(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment