Let m and n be two different positive integers in reverse order (e.g. 1 2 3 4 and 4 3 2 1 ). Given that m n = 2 4 6 0 3 0 1 0 5 6 , find the value of m + n .
Details and Assumptions :
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
the same method but don't you think this must be cheating? Because I don't think you must be knowing the prime factorization of the number or you must have found it.
@Yuxuan Seah What was the intended solution?
BTW, I'm curious to know why did the asker of the question mentioned that
You may use a List of Primes
Was it intended to be a CS problem or Number Theory problem?
Since the digit is a 10 digit number and the last digit is not 0, both the numbers must be 5-digits, so I tried for integer all the way to 99999 but it only takes 1 second. Here is my Python solution: ;)
def reverse_int(number): #function to reverse an integer a = 0 b = 0 c = 0 d = 0 e = 0 while number - 10000>=0: e = e + 1 number = number - 10000 while number - 1000>=0: a = a + 1 number = number - 1000 while number - 100>=0: b = b + 1 number = number - 100 while number - 10>=0: c = c + 1 number = number - 10 while number - 1>=0: d = d + 1 number = number - 1 reverse = 10000 d + 1000 c + 100 b + 10 a + e return reverse
for i in range(99999): #testing for integer up to 99999 k = i k = reverse_int(k) if i*k == 2460301056: print(str(i) + " and " + str(k)) else: pass
So you get: 27498 and 89472 and the sum is 116970.
Sorry but the indentation is a bit wrong...
Impressive :D
While you're at it, shouldn't you make a reverse-function for integers of arbitrarily many digits? It would then be something like this. (I'm not sure why formatting doesn't work; if I do what's suggested in the formatting guide, it doesn't get any better, though. :()
def revert(n):
a=len(str(n))-1
b=0
while n:
c=n%10
b+=c*10**a
a-=1
n/=10
return b
Dummy=False
i=1
while Dummy==False:
if i*revert(i)==2460301056:
print i,i+revert(i)
Dummy=True
i+=1
... Here's a hint: The two numbers are 27498 and 89472. I'm so sorry but that's all I can say; the rest is up to the solver to figure out. (Good luck finding it!)
Can't spoil the fun, can I? ;D
1 2 3 |
|
This is a dreadful brute force hack. Surely it's only necessary to check for solutions somewhere closer to the square root of mn?
Python:
1 2 3 4 5 6 |
|
Problem Loading...
Note Loading...
Set Loading...
Firstly, 2 4 6 0 3 0 1 0 5 6 = 2 8 × 3 2 × 2 3 3 × 4 5 8 3 .
Since both m and n have the same number of digits, they must have 5 digits each.
Also, one of the factors is 4 5 8 3 , and 4 5 8 3 × 2 3 3 > 9 9 9 9 9 .
So one of the numbers (say m ) must be of the form 4 5 8 3 a where a is an integer and n must be of the form 2 3 3 b where b is an integer.
Since 4 5 8 3 9 9 9 9 9 < 2 2 and 4 5 8 3 1 0 0 0 0 > 2 , a can only take the value of 2 2 , 2 3 , 2 4 , 2 × 3 , 2 2 × 3 and 2 × 3 2 .
Testing, we find that a = 2 × 3 = 6 yields m = 2 7 4 9 8 and subsequently n = 2 3 3 × ( 2 7 ) ( 3 ) = 8 9 4 7 2 . We have our desired answer 2 7 4 9 8 + 8 9 4 7 2 = 1 1 6 9 7 0 .