The number 24 has a special property: all of its digits appear at the end of its cube, 138 24 , in the same order.
How many positive integers less than 1000 (including the number 24) have this property?
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.
Nice solution! You said that all two-digit numbers that satisfy the congruences are "all of the form 25k +- 1 for some nonnegative k", but the numbers 25 and 75 also satisfy the conditions and are not in that form. Do you mean "all of the form 25k +- 1 or 25k"? (Likewise, for three-digit numbers "or 125k"?)
What just happened?
Very smart indeed
1 2 3 4 5 6 7 |
|
k = 2 5
I did a program in my calculator. It was awesome
you could have used ceil(•) instead of floor(•)+1
Log in to reply
If using ceil(.), the program will output powers of 10 as satisfying the condition, but they don't.
By direct calculation, the single digits with this property are 0 , 1 , 4 , 5 , 6 , and 9 (its cubes are 0, 1, 64, 125, 216, and 729 respectively).
For two digit numbers, if we will let a be the first digit and b be the last digit, then ( 1 0 a + b ) 3 ≡ 1 0 a + b m o d 1 0 0 would describe this property, and this simplifies to ( 3 b 2 − 1 ) a ≡ 1 0 b − b 3 m o d 1 0 . Two digit numbers with this property must end in the single digits with this property, so we can use this formula by setting b equal to the single digits listed above and solving for a . Therefore:
If b = 0 , then 9 a ≡ 0 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 0 , for 00 (a repeat, and not positive).
If b = 1 , then 2 a ≡ 0 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 0 or a = 5 , for 01 (a repeat) and 51 .
If b = 4 , then 7 a ≡ 4 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 2 , for 24 .
If b = 5 , then 4 a ≡ 8 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 2 or a = 7 , for 25 and 75 .
If b = 6 , then 7 a ≡ 9 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 7 , for 76 .
If b = 9 , then 2 a ≡ 8 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 4 or a = 9 , for 49 and 99 .
For three digit numbers, if we let a be the first digit and b be the value of the last two digits, then ( 1 0 0 a + b ) 3 ≡ 1 0 0 a + b m o d 1 0 0 0 would describe this property, and this simplifies to ( 3 b 2 − 1 ) a ≡ 1 0 0 b − b 3 m o d 1 0 . Three digit numbers with this property must end in the two digit numbers with this property, so we can use this formula by setting b equal to the two digit numbers listed above and solving for a . Therefore:
If b = 0 0 , then 9 a ≡ 0 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 0 , for 000 (a repeat, and not positive).
If b = 0 1 , then 2 a ≡ 0 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 0 or a = 5 , for 001 (a repeat) and 501 .
If b = 2 4 , then 7 a ≡ 2 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 6 , for 624 .
If b = 2 5 , then 4 a ≡ 4 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 1 or a = 6 , for 125 and 625 .
If b = 4 9 , then 2 a ≡ 4 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 2 or a = 7 , for 249 and 749 .
If b = 5 1 , then 2 a ≡ 4 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 2 or a = 7 , for 251 and 751 .
If b = 7 5 , then 4 a ≡ 2 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 3 or a = 8 , for 375 and 875 .
If b = 7 6 , then 7 a ≡ 1 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 3 , for 376 .
If b = 9 9 , then 2 a ≡ 8 m o d 1 0 for 0 ≤ a ≤ 9 , so a = 4 or a = 9 , for 499 and 999 .
The positive integers less than 1000 that have all of its digits also appear at the end of its cube in the same order are 1, 4, 5, 6, 9, 24, 25, 49, 51, 75, 76, 99, 125, 249, 251, 375, 376, 499, 501, 624, 625, 749, 751, 875, and 999 for a total of 2 5 different numbers.
small typo : you wrote 6 2 5 twice at the end instead of 6 2 4 , 6 2 5 .
A lazy solution in python 3:
count = 0
for i in range(1, 1000):
cube = i ** 3
if str(cube)[-len(str(i)):] == str(i):
print("The cube of %s is %s" % (str(i), str(cube)))
count += 1
print("The total number found is: " + str(count))
brute force with a calculator is not too hard:
1 digit: 1, 4, 5, 6, 9
extend each of the above to 2 digits: 51, 24, 25, 75, 46, 49, 99
extend all of the above to 3 digits
501, 251, 751, 624, 125, 625, 375, 875, 376, 249, 749, 499, 999
(I almost missed 501 by forgetting to expand 1 to 3 digits. I caught it by noticing they come in pairs that add to 10, 100, and 1000 with the sole exception of 5.)
It is better to read the Number theory answer. However, when considering this problem is just in a small scale as 1000, the cube will only reach 10^9. Hence, it can be solved using brute force by a simple program.
Here's python implementation of the brute-force solution, you can paste this solution to the web environment here on brilliant :
import math
sum = 0
for num in range(1, 1000):
cube = pow(num, 3)
num_length = int(math.log10(num)) + 1
last_digits_of_cube = cube % pow(10, num_length)
if last_digits_of_cube == num:
sum += 1
# print(str(num) + " has the cube of " + str(cube)) # Show each answer; can be commented.
print(sum)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Mathematica
Select[Range@1000, FromDigits[IntegerDigits[#^3, 10, IntegerLength@#]] == # &]
{1,4,5,6,9,24,25,49,51,75,76,99,125,249,251,375,376,499,501,624,625,749,751,875,999}
main() { long int n,v=0,k=0,c=0; int q,i=10,p=0; for(n=1;n<1000;n++) { k=n; v=n n n; c=v-n; if (n<10) q=c%10; else { if (n<100 && n>9) q=c%100; else q=c%1000; } if (q==0) p++; } printf("\n %d",p); getch(); }
A simple solution in R:
1 2 3 4 5 6 7 |
|
Lazy but adaptable Excel Solution
Column 1 , 1-999.
Column 2 , (1-999)^3
Column 3 , Used =RIGHT(value,#chars) to cut off the last one, two and three values according to number of corresponding decimals in the first column.
Then =LEN function is used to determine how many characters are cut off of the #Rightmost values of Column 2 for Column 3.
Column 4 , Checks if matching, 1 for true 0 for false.
Used =SUM(Column4) to count matches.
I wrote an AWK script, which produced the number 25.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
25 numbers
Coding via Dev C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
A one-line python solution. Pretty simple for an advanced problem to be honest.
I just used the string constructor str() , in order to easily check if the final digits of the cube are equal to the initial integer.
1 2 3 4 5 |
|
Answer: 2 5
Very lazy solution, which yields the result, 25 :
1 |
|
This makes use of:
str.endswith()
method
.
Wow, only one line of code! Impressive!
1 2 3 4 5 |
|
[ 1 , 4 , 5 , 6 , 9 , 2 4 , 2 5 , 4 9 , 5 1 , 7 5 , 7 6 , 9 9 , 1 2 5 , 2 4 9 , 2 5 1 , 3 7 5 , 3 7 6 , 4 9 9 , 5 0 1 , 6 2 4 , 6 2 5 , 7 4 9 , 7 5 1 , 8 7 5 , 9 9 9 ] l e n g t h : 2 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
Problem Loading...
Note Loading...
Set Loading...
For single-digit numbers, we have x 3 ≡ x mod 1 0 , which translates to x ≡ 0 , ± 1 mod 5 . There are five numbers in the range [ 1 , 9 ] satisfying that congruence.
For two-digit numbers, we have x 3 ≡ x mod 1 0 0 , which translates to 2 5 ∣ x ( x − 1 ) ( x + 1 ) and 4 ∣ x ( x − 1 ) ( x + 1 ) . This means x ≡ 0 , ± 1 mod 2 5 and x ≡ 0 , ± 1 mod 4 . There are nine numbers mod 1 0 0 that satisfy these congruences (by the Chinese Remainder Theorem ). They're all of the form 2 5 k or 2 5 k ± 1 for some nonnegative integer k , so the only ones less than 1 0 that work are 0 and 1 , so there are seven two-digit numbers.
For three-digit numbers, we have x 3 ≡ x mod 1 0 0 0 , which translates to 1 2 5 ∣ x ( x − 1 ) ( x + 1 ) and 8 ∣ x ( x − 1 ) ( x + 1 ) . This means x ≡ 0 , ± 1 mod 1 2 5 and x ≡ 0 , 1 , 3 , 5 , 7 mod 8 . There are fifteen numbers mod 1 0 0 0 satisfying these congruences (by the Chinese Remainder Theorem ). They're all of the form 1 2 5 k or 1 2 5 k ± 1 for some nonnegative integer k , so the only ones less than 1 0 0 that work are, again, 0 and 1 . That leaves thirteen three-digit numbers.
So the final answer is 1 3 + 7 + 5 = 2 5 .