Associated Topics || Dr. Math Home || Search Dr. Math

### Perfect Square?

```
Date: 02/18/2002 at 14:34:15
From: charles

If we use the digits 1,2,3,4,5,6,7 each only once to form a 7-digit
number, can the resulting number be a perfect square?
```

```
Date: 02/18/2002 at 20:47:51
From: Doctor Paul

No. There are 7! = 5040 different ways to write a number that contains
each of these digits exactly once.

I had Maple (a math programming language) do this for me:

> restart;
> with(combinat, permute);

[permute]

>
> K:=permute(7,7):
> nops(K);

5040

> K[1];

[1, 2, 3, 4, 5, 6, 7]

I created an array and called it K. K contains all 5040 permutions of
the elements 1 through 7. But they aren't in integer format - they're
in arrays.

Just so you get the idea, the first couple of lines of K look like
this:

[[1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 7, 6],

[1, 2, 3, 4, 6, 5, 7], [1, 2, 3, 4, 6, 7, 5],

[1, 2, 3, 4, 7, 5, 6], [1, 2, 3, 4, 7, 6, 5],

[1, 2, 3, 5, 4, 6, 7], [1, 2, 3, 5, 4, 7, 6],

[1, 2, 3, 5, 6, 4, 7], [1, 2, 3, 5, 6, 7, 4],

[1, 2, 3, 5, 7, 4, 6], [1, 2, 3, 5, 7, 6, 4],

so what we need to do is convert each of these to integers and then
check to see if it's a perfect square.

To convert to an integer, just take each one and do something like the
following:

7 + 6*10 + 5*10^2 + 4*10^3 + 3*10^4 + 2*10^5 + 1*10^6 = 1,234,567

I did this in Maple as well. I converted each array to an integer and
then checked to see if it was a perfect square by seeing if the
fractional part of its square root was zero:

> for i from 1 to 5040 do
> m:=0:
>   for j from 1 to 7 do
>   m:=m + K[i][j] * 10^(7-j);
>   if j = 7 and frac(sqrt(m)) = 0 then print(m) fi;
>   od:
> od:

Inasmuch as the output was blank, none of the 5040 combinations yields
a perfect square.

If you'd like to talk some more about my answer, feel free to write
back.

- Doctor Paul, The Math Forum
http://mathforum.org/dr.math/
```
Associated Topics:
High School Number Theory

Search the Dr. Math Library:

 Find items containing (put spaces between keywords):   Click only once for faster results: [ Choose "whole words" when searching for a word like age.] all keywords, in any order at least one, that exact phrase parts of words whole words

Submit your own question to Dr. Math
Math Forum Home || Math Library || Quick Reference || Math Forum Search