Automorphic Cubes

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?


The answer is 25.

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.

20 solutions

Patrick Corn
Jan 18, 2018

For single-digit numbers, we have x 3 x x^3 \equiv x mod 10 , 10, which translates to x 0 , ± 1 x \equiv 0, \pm 1 mod 5. 5. There are five numbers in the range [ 1 , 9 ] [1,9] satisfying that congruence.

For two-digit numbers, we have x 3 x x^3 \equiv x mod 100 , 100, which translates to 25 x ( x 1 ) ( x + 1 ) 25|x(x-1)(x+1) and 4 x ( x 1 ) ( x + 1 ) . 4|x(x-1)(x+1). This means x 0 , ± 1 x \equiv 0, \pm 1 mod 25 25 and x 0 , ± 1 x \equiv 0, \pm 1 mod 4. 4. There are nine numbers mod 100 100 that satisfy these congruences (by the Chinese Remainder Theorem ). They're all of the form 25 k 25k or 25 k ± 1 25k \pm 1 for some nonnegative integer k , k, so the only ones less than 10 10 that work are 0 0 and 1 1 , so there are seven two-digit numbers.

For three-digit numbers, we have x 3 x x^3 \equiv x mod 1000 , 1000, which translates to 125 x ( x 1 ) ( x + 1 ) 125|x(x-1)(x+1) and 8 x ( x 1 ) ( x + 1 ) . 8|x(x-1)(x+1). This means x 0 , ± 1 x \equiv 0, \pm 1 mod 125 125 and x 0 , 1 , 3 , 5 , 7 x \equiv 0, 1, 3, 5, 7 mod 8. 8. There are fifteen numbers mod 1000 1000 satisfying these congruences (by the Chinese Remainder Theorem ). They're all of the form 125 k 125k or 125 k ± 1 125k \pm 1 for some nonnegative integer k , k, so the only ones less than 100 100 that work are, again, 0 0 and 1. 1. That leaves thirteen three-digit numbers.

So the final answer is 13 + 7 + 5 = 25 . 13 + 7 + 5 = \fbox{25}.

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"?)

David Vreken - 3 years, 4 months ago

Log in to reply

Thanks, fixed.

Patrick Corn - 3 years, 4 months ago

What just happened?

Desmond Campbell - 3 years, 4 months ago

Very smart indeed

ZHI SHU - 3 years, 4 months ago
1
2
3
4
5
6
7
k = 0 ;
for m = 1:999
    if mod(m^3-m,10^(floor(log(m)/log(10))+1))==0
        k = k+1 ;
    end
end
k 

k = 25 \boxed{k=25}

I did a program in my calculator. It was awesome

Maria Isabel Lopez - 3 years, 4 months ago

you could have used ceil(•) instead of floor(•)+1

Lee Isaac - 3 years, 3 months ago

Log in to reply

If using ceil(.), the program will output powers of 10 as satisfying the condition, but they don't.

Olivier Vincent - 3 years, 3 months ago
David Vreken
Jan 17, 2018

By direct calculation, the single digits with this property are 0 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 a be the first digit and b b be the last digit, then ( 10 a + b ) 3 10 a + b m o d 100 (10a + b)^3 \equiv 10a + b \mod{100} would describe this property, and this simplifies to ( 3 b 2 1 ) a b b 3 10 m o d 10 (3b^2 - 1)a \equiv \frac{b - b^3}{10} \mod{10} . Two digit numbers with this property must end in the single digits with this property, so we can use this formula by setting b b equal to the single digits listed above and solving for a a . Therefore:

If b = 0 b = 0 , then 9 a 0 m o d 10 9a \equiv 0 \mod {10} for 0 a 9 0 \leq a \leq 9 , so a = 0 a = 0 , for 00 (a repeat, and not positive).

If b = 1 b = 1 , then 2 a 0 m o d 10 2a \equiv 0 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 0 a = 0 or a = 5 a = 5 , for 01 (a repeat) and 51 .

If b = 4 b = 4 , then 7 a 4 m o d 10 7a \equiv 4 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 2 a = 2 , for 24 .

If b = 5 b = 5 , then 4 a 8 m o d 10 4a \equiv 8 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 2 a = 2 or a = 7 a = 7 , for 25 and 75 .

If b = 6 b = 6 , then 7 a 9 m o d 10 7a \equiv 9 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 7 a = 7 , for 76 .

If b = 9 b = 9 , then 2 a 8 m o d 10 2a \equiv 8 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 4 a = 4 or a = 9 a = 9 , for 49 and 99 .

For three digit numbers, if we let a a be the first digit and b b be the value of the last two digits, then ( 100 a + b ) 3 100 a + b m o d 1000 (100a + b)^3 \equiv 100a + b \mod{1000} would describe this property, and this simplifies to ( 3 b 2 1 ) a b b 3 100 m o d 10 (3b^2 - 1)a \equiv \frac{b - b^3}{100} \mod{10} . 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 b equal to the two digit numbers listed above and solving for a a . Therefore:

If b = 00 b = 00 , then 9 a 0 m o d 10 9a \equiv 0 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 0 a = 0 , for 000 (a repeat, and not positive).

If b = 01 b = 01 , then 2 a 0 m o d 10 2a \equiv 0 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 0 a = 0 or a = 5 a = 5 , for 001 (a repeat) and 501 .

If b = 24 b = 24 , then 7 a 2 m o d 10 7a \equiv 2 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 6 a = 6 , for 624 .

If b = 25 b = 25 , then 4 a 4 m o d 10 4a \equiv 4 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 1 a = 1 or a = 6 a = 6 , for 125 and 625 .

If b = 49 b = 49 , then 2 a 4 m o d 10 2a \equiv 4 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 2 a = 2 or a = 7 a = 7 , for 249 and 749 .

If b = 51 b = 51 , then 2 a 4 m o d 10 2a \equiv 4 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 2 a = 2 or a = 7 a = 7 , for 251 and 751 .

If b = 75 b = 75 , then 4 a 2 m o d 10 4a \equiv 2 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 3 a = 3 or a = 8 a = 8 , for 375 and 875 .

If b = 76 b = 76 , then 7 a 1 m o d 10 7a \equiv 1 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 3 a = 3 , for 376 .

If b = 99 b = 99 , then 2 a 8 m o d 10 2a \equiv 8 \mod{10} for 0 a 9 0 \leq a \leq 9 , so a = 4 a = 4 or a = 9 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 25 \boxed{25} different numbers.

small typo : you wrote 625 625 twice at the end instead of 624 , 625 624, 625 .

Romain Bouchard - 3 years, 4 months ago

Log in to reply

Thank you! I fixed it.

David Vreken - 3 years, 4 months ago
Peter Macgregor
Jan 30, 2018

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))
Jeremy Galvagni
Feb 4, 2018

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.)

Richard Lau
Feb 4, 2018

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)
Haris Zaharakis
Feb 4, 2018
 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
"use strict";
//n = the number we are testing & ncubed = its cubic form
var n,ncubed;
//nl = digits of the number we are testing & ncl = digits of the number cubed
var nl,ncl;
//t = total numbers that satisfy our condition
var t = 0;
for(var i=1; i<1000; i++)
{
    n = i;
    ncubed = Math.pow(n,3);
    //convert numbers to strings
    n = n.toString();
    ncubed = ncubed.toString();
    //measure their lengths
    nl = n.length;
    ncl = ncubed.length;
    //check condition
    if(ncubed.substring(ncl-nl,ncl) == n)
    {
        console.log(n+" , "+ncubed);
        t++;
    }
}
console.log("total of "+t+" numbers.");

Giorgos K.
Feb 4, 2018

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}

include<stdio.h>

include<conio.h>

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(); }

Anas Emad
Feb 2, 2018

A simple solution in R:

1
2
3
4
5
6
7
n = 0
for (i in 1:999) {
        if (i^3 %% 10^nchar(i) == i) {
                n = n + 1
        }
}
print(n)

Heshu Wang
Feb 2, 2018

https://oeis.org/A033819

Elijah Shervey
Feb 1, 2018

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.

  • Answer = 25.
Bert Seegmiller
Feb 1, 2018

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
# to get the answer to a puzzle at Brilliant
#
#  the cube 24 problem: that all the digits of a number appear at
#  the end of its cube, i.e.:
#    24^3 => 13824
#  -- for all positive integers less than 1000.
#

BEGIN {
  count = 0;
  for ( t=1 ; t < 1000; t++ ) {
    tstr = t "";
    t3 = t*t*t;
    t3str = t3 "";
    found = index( t3 "", t "" );
    if ( found > 0 ) {
      if ( 0 == found ) print " found == " found " at " tstr;
      # print t "" " in " t3 "" " at " found;
      if ( ( length(t3 "") + 1 - length(t "") ) == found ) {
        count++;
        print count ": " t "" " in " t3 "" " at " found ;
      }
      if ( 0 == found ) print " found == " found " at " t " (after)";
    }
  }
  print count " numbers";
  exit(0);
  }

END {
  }

 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
1: 1 in 1 at 1
2: 4 in 64 at 2
3: 5 in 125 at 3
4: 6 in 216 at 3
5: 9 in 729 at 3
6: 24 in 13824 at 4
7: 25 in 15625 at 4
8: 49 in 117649 at 5
9: 51 in 132651 at 5
10: 75 in 421875 at 5
11: 76 in 438976 at 5
12: 99 in 970299 at 5
13: 125 in 1953125 at 5
14: 249 in 15438249 at 6
15: 251 in 15813251 at 6
16: 375 in 52734375 at 6
17: 376 in 53157376 at 6
18: 499 in 124251499 at 7
19: 501 in 125751501 at 7
20: 624 in 242970624 at 7
21: 625 in 244140625 at 7
22: 749 in 420189749 at 7
23: 751 in 423564751 at 7
24: 875 in 669921875 at 7
25: 999 in 997002999 at 7

25 numbers

Bernard Peh
Feb 1, 2018

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
#include<stdio.h>
#include<conio.h>
#include<iostream>
#include<math.h>
unsigned int nm=1,dg,mod,power10,nm3,total=1;
main()
{
while(nm<1000)
    {
    using namespace std;
    dg=ceil(log10(nm));

    if(dg==floor(log10(nm)))
        dg=dg+1;

    power10=ceil(pow(10,dg));
    nm3=ceil(pow(nm,3));
    mod=nm3%power10;
    if(mod-nm==0)
    {
        printf("%d satisfies the criteria.[%d]\n",nm,total);
        total=total+1;
    }
    nm=nm+1;
    }
}

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
n=0
for i in range(1,1000):
    if str(i) == str(i**3)[-len(str(i)):]:
        n+=1
print('Total:',n) 

Answer: 25 \boxed{25}

Victor Dumbrava
Jan 31, 2018

Very lazy solution, which yields the result, 25 :

1
print(sum([str(i**3).endswith(str(i)) for i in range(1, 1000)]))

Try it here!

This makes use of:

Wow, only one line of code! Impressive!

David Vreken - 3 years, 4 months ago
Ovidiu Dumitrescu
Jan 31, 2018
1
2
3
4
5
v=[]
for n in 1...1000
  v<<n if n==(n**3)%(10**(Math.log10(n).to_i+1))
end
puts "#{v} length: #{v.length}" 

[ 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 ] l e n g t h : 25 [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] length: \boxed{25}

Alex Li
Jan 30, 2018
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    public static void main(String[] args) {
        int count = 0;
        for (int i = 1; i < 10; i++) {
            if((i*i*i)%10 == i) {
                count++;
            }
        }
        for (int i = 10; i < 100; i++) {
            if((i*i*i)%100 == i) {
                count++;
            }
        }
        for (int i = 100; i < 1000; i++) {
            if((i*i*i)%1000 == i) {
                count++;
            }
        }
        System.out.println(count);
    } 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
max_ = 1000
count_int = 0
for i in range(1, max_):
    y = i**3
    if str(y)[-len(str(i)):] == str(i):
        print i, y
        count_int += 1

print"""
Number of positive integers less than %d that have all of its digits 
appear at the end of its cube in the same order is %d
""" %(max_, count_int)

 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 1
4 64
5 125
6 216
9 729
24 13824
25 15625
49 117649
51 132651
75 421875
76 438976
99 970299
125 1953125
249 15438249
251 15813251
375 52734375
376 53157376
499 124251499
501 125751501
624 242970624
625 244140625
749 420189749
751 423564751
875 669921875
999 997002999

Number of positive integers less than 1000 that have all of its digits 
appear at the end of its cube in the same order is 25

Parth Shah
Jan 29, 2018
 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
'''java
import java.util.*;
public class cubespec
{
    static void main()
    {
        String s="",s1="",s2="";
        int c=0,cube;        
        for(int i=0;i<=999;i++)
        {
            s1="";
            s2="";
            cube=i*i*i;
            s=s+cube;
            s2=s2+i;
            int l=s.length();
            if(i<10 && i>=1)
            {
                s1=s1+s.charAt(l-1);                               
            }
            if(i<100 && i>=11)
            {
                s1=s1+s.charAt(l-2)+s.charAt(l-1);               
            }
            if(i<1000 && i>=101)
            {
                s1=s1+s.charAt(l-3)+s.charAt(l-2)+s.charAt(l-1);               
            }
            if(s1.equals(s2))
            {
                    c++;
                    System.out.println("Special number "+i+" its cube "+cube);
            } 
        }
        System.out.println("The number of special cubes are="+c);
    }
} 

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...