HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Factorials, Irrational Numbers, Digits and the Floor Function
  1. 1The floor function and Legendre's formula
  2. 2Rational and irrational numbers
  3. 3Digits, bases, squares and cubes
  1. Mathematics
  2. /Factorials, Irrational Numbers, Digits and the Floor Function
  3. /Digits, bases, squares and cubes

Course 27.3·Lesson 3 of 3

Digits, bases, squares and cubes

Any number can be written in any base b≥2b \ge 2b≥2 by repeated division, and its digits are remainders. A digit problem becomes algebra once you write abc‾=100a+10b+c\overline{abc} = 100a + 10b + cabc=100a+10b+c

Lesson 3 of 3Show all lessonsHide
Factorials, Irrational Numbers, Digits and the Floor Function
  1. 1The floor function and Legendre's formula
  2. 2Rational and irrational numbers
  3. 3Digits, bases, squares and cubes

Try the code and the simulations beside the lesson.

What you will be able to do

  • write a number in base bbb and back, and count its digits;
  • turn a digit puzzle into an equation;
  • prove that a number is not a square or a cube from its remainders, or by placing it between two consecutive squares.

Counting in other bases

We count in tens because we have ten fingers. A computer counts in twos. In base bbb, a number with digits dk…d1d0d_k \dots d_1 d_0dk​…d1​d0​, each from 000 to b−1b - 1b−1, means

dkbk+⋯+d1b+d0.\displaystyle d_k b^k + \dots + d_1 b + d_0.dk​bk+⋯+d1​b+d0​.

We write the base as a small number below: 1011012=32+8+4+1=45101101_2 = 32 + 8 + 4 + 1 = 451011012​=32+8+4+1=45.

To convert nnn into base bbb, divide by bbb again and again. The remainders, read from the last to the first, are the digits. For 123412341234 in base 777:

  1. 1234=7×176+21234 = 7 \times 176 + 21234=7×176+2, so the units digit is 222.
  2. 176=7×25+1176 = 7 \times 25 + 1176=7×25+1, so the next digit is 111.
  3. 25=7×3+425 = 7 \times 3 + 425=7×3+4, and then 3=7×0+33 = 7 \times 0 + 33=7×0+3.

So 1234=341271234 = 3412_71234=34127​. Check: 3×343+4×49+1×7+2=12343 \times 343 + 4 \times 49 + 1 \times 7 + 2 = 12343×343+4×49+1×7+2=1234.

The number of digits. A number N≥1N \ge 1N≥1 has kkk digits in base 101010 exactly when 10k−1≤N<10k10^{k-1} \le N < 10^k10k−1≤N<10k. So it has ⌊log⁡10N⌋+1\lfloor \log_{10} N \rfloor + 1⌊log10​N⌋+1 digits. In base bbb use log⁡bN\log_b Nlogb​N instead.

Digit puzzles

Name the digits and write the number as a sum. A two-digit number is ab‾=10a+b\overline{ab} = 10a + bab=10a+b.

  • ab‾−ba‾=9(a−b)\overline{ab} - \overline{ba} = 9(a - b)ab−ba=9(a−b), always a multiple of 999.
  • abc‾−cba‾=99(a−c)\overline{abc} - \overline{cba} = 99(a - c)abc−cba=99(a−c), a multiple of 999999.

Worked example. A two-digit number is 444 times the sum of its digits. Find all such numbers.

  1. Set up. 10a+b=4(a+b)10a + b = 4(a + b)10a+b=4(a+b), so 6a=3b6a = 3b6a=3b, which gives b=2ab = 2ab=2a.
  2. List. aaa from 111 to 444 keeps bbb a digit: 12,24,36,4812, 24, 36, 4812,24,36,48.
  3. Check. 36=4×936 = 4 \times 936=4×9 and 3+6=93 + 6 = 93+6=9.

What squares can and cannot be

The last digit of n2n^2n2 depends only on the last digit of nnn. Squaring 000 to 999 gives last digits 0,1,4,9,6,5,6,9,4,10, 1, 4, 9, 6, 5, 6, 9, 4, 10,1,4,9,6,5,6,9,4,1. So a square never ends in 222, 333, 777 or 888.

Remainders tell even more. Sorting nnn by its remainder, as in course 1:

Divide byA square leavesA cube leaves
3330,10, 10,10,1,20, 1, 20,1,2
4440,10, 10,10,1,30, 1, 30,1,3
8880,1,40, 1, 40,1,40,1,3,5,70, 1, 3, 5, 70,1,3,5,7
9990,1,4,70, 1, 4, 70,1,4,70,1,80, 1, 80,1,8
A bar chart of the remainders 0 to 8 on division by 9. Blue bars show how many of the squares of 0 to 899 leave each remainder; only 0, 1, 4 and 7 have bars. Orange bars show the same for cubes; only 0, 1 and 8 have bars. The other remainders have no bar at all.

Examples of use.

  • 22,222,2222,…22, 222, 2222, \dots22,222,2222,… are never squares. Each leaves remainder 222 on division by 444, because its last two digits are 222222.
  • A number whose digit sum is 333 more than a multiple of 999 is never a square or a cube. Its remainder on division by 999 is 333, and neither column contains 333.
  • The sum of three cubes leaves 0,1,2,3,6,70, 1, 2, 3, 6, 70,1,2,3,6,7 or 888 on division by 999, never 444 or 555.

Squeezing between squares

There is no square strictly between m2m^2m2 and (m+1)2(m + 1)^2(m+1)2. So if you can show

m2<N<(m+1)2,\displaystyle m^2 < N < (m + 1)^2,m2<N<(m+1)2,

then NNN is not a square.

Example. For n≥1n \ge 1n≥1, n2<n2+n+1<n2+2n+1=(n+1)2n^2 < n^2 + n + 1 < n^2 + 2n + 1 = (n + 1)^2n2<n2+n+1<n2+2n+1=(n+1)2. So n2+n+1n^2 + n + 1n2+n+1 is never a square for n≥1n \ge 1n≥1.

When the squeeze has gaps, factorise. Find all n≥1n \ge 1n≥1 with n2+6n+20n^2 + 6n + 20n2+6n+20 a square m2m^2m2. Write it as (n+3)2+11=m2(n + 3)^2 + 11 = m^2(n+3)2+11=m2, so (m−n−3)(m+n+3)=11(m - n - 3)(m + n + 3) = 11(m−n−3)(m+n+3)=11. As 111111 is prime and m+n+3>0m + n + 3 > 0m+n+3>0, the factors are 111 and 111111. Then m=6m = 6m=6 and n=2n = 2n=2. Check: 4+12+20=364 + 12 + 20 = 364+12+20=36.

Practise with new numbers

Try it in Python

The program converts numbers into other bases and lists the remainders of squares and cubes, which fill the table above.

Read it first. Then run it. Do the lists match the table?

1. Add 7 to the list [4, 8, 9]. Which remainders can a square leave on division by 777?

2. Check that no number 22…222\dots222…2 with up to 303030 digits is a square: use math.isqrt(n) ** 2 == n.

Common mistakes

  • Writing ab‾\overline{ab}ab as ababab. It means 10a+b10a + b10a+b, not a×ba \times ba×b.
  • Reading the base-bbb digits in the wrong order. The first remainder is the units digit.
  • Using one remainder test only. A number may pass the test for 444 and fail the one for 999. Try several.
  • Squeezing with a loose bound. Check that both inequalities hold for every nnn in your range, and test the small nnn by hand.

Remember these

  • In base bbb, the digits are the remainders of repeated division by bbb.
  • A number N≥1N \ge 1N≥1 has ⌊log⁡10N⌋+1\lfloor \log_{10} N \rfloor + 1⌊log10​N⌋+1 digits.
  • abc‾−cba‾=99(a−c)\overline{abc} - \overline{cba} = 99(a - c)abc−cba=99(a−c).
  • Squares leave 0,10, 10,1 on division by 444 and 0,1,4,70, 1, 4, 70,1,4,7 on division by 999; cubes leave 0,1,80, 1, 80,1,8 on division by 999.
  • There is no square strictly between m2m^2m2 and (m+1)2(m + 1)^2(m+1)2.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Write 100100100 in base 333.
  1. How many digits does 2302^{30}230 have? Use log⁡102≈0.30103\log_{10} 2 \approx 0.30103log10​2≈0.30103.
  1. Can a square end in the digits …7\dots 7…7?
  1. Show that n2+3n+3n^2 + 3n + 3n2+3n+3 is never a square for n≥1n \ge 1n≥1.
  1. A number has digit sum 200320032003. Can it be a perfect cube?

References

  • David M. Burton, Elementary Number Theory, Chapter 4, section 4.3 on number bases and the remainders of squares.
  • Arthur Engel, Problem-Solving Strategies, Chapter 6 on number theory, for squares, digits and bounding.

Enroll free in Factorials, Irrational Numbers, Digits and the Floor Function

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (4)

Take a three-digit number abc whose first and last digits differ by at least 2…Hard · High School (11–12) · by StemPy Lab
Prove that none of 11, 111, 1111, … is a perfect square…Advanced · High School (11–12) · by StemPy Lab
Prove that 121b is a perfect square in every base b ≥ 3…Hard · High School (11–12) · by StemPy Lab
That was the last lessonBack to the course: take the test
← Factorials, Irrational Numbers, Digits and the Floor Function
← Rational and irrational numbersNext →

Discussion (0)

Log in to join the discussion.

Loading…

. Squares leave only certain remainders:
000
or
111
on division by
444
,
0,1,4,70, 1, 4, 70,1,4,7
on division by
999
, and cubes leave
0,1,80, 1, 80,1,8
on division by
999
. Bounding a number strictly between two consecutive squares proves it is not a square.
about 25 min1 simulation1 practice question1 Python program5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

Find all positive whole numbers n for which n² + 5n + 30 is a perfect square…Advanced · High School (11–12) · by StemPy Lab

Python Labs (1)

Bases and squaresPython Lab · by StemPy Lab

Question Sets (1)

Factorials, Digits and Squares: Test Yourself10 questions · by StemPy Lab

Notes (1)

Factorials, Irrational Numbers, Digits and the Floor Function: Quick RevisionNote · by StemPy Lab