Find the ONLY
5-digit positive integer
that has ALL of the following properties:
i) It is a square number
ii) The digits are in an increasing sequence
iii) Each digit of the number is a perfect square
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.
Any square digit implies only three possible numbers 1,4,9; and we all know that for a number to be a perfect square it has to be either divisible by 4 or gives remainder 1 with 4 as divisor. So the last two digits must be 49 (as 99 does not satisfy the condition above) . There fore the possibilities are 1xy49 , where x,y can be 1 or 4. (a+b)^2= a^2+b^2 +2ab Set a=100. To find out b, square(100)=10000 and square(130)=16900 hence b can only be 7 from the condition that only b^2 can produce last two digits. Hence the number is (100+7)^2 = 11449
Log in to reply
Nice! But only one question, why did you set a=100 from the beginning?
Here is a rather primitively done solution:
The requirement that each digit had to be a square number meant that only five digit numbers containing the digits 1, 4, 9 would satisfy. The requirement that they be ordered further limited the possibilities. I then tested possibilities 44444-99999 as these were just six possibilities. Once I deduced that the first digit had to start with 1, I started squaring numbers beginning with 100, 101...107^2 = 11449 which satisfies the requirements for this problem.
11449 does not satisfy the the requirement that the digits be in an increasing sequence. It is only non decreasing.
Why 144 is incorrect ?
Log in to reply
Coz it has to be a 5 digit number.
It asks for positive integers, and 0 is not a positive integer
find 5 digit number
Because questions is find the five digit positive no.. And ur ans in 3 digit..
asked fr a 5 digit no.
5 digit number
thats what i do
It can also contain 0
Log in to reply
Actually, no. I don't think so. It is increasing in sequence. So in no way, 0 is included here
The smallest possible 5 digit number, where each digit is a square number is 11111. The square root of this is approximately 105.4. Set up a spreadsheet to calculate the squares of numbers greater than 105. The answer is 11449, which is the square of 107.
This is Java:
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 |
|
1 2 3 4 5 6 7 |
|
Freaky Square :P
Java solution -
for(int i = 10_000; i < 100_000; i++)
if(Math.round(Math.sqrt(i))==Math.sqrt(i))
if (String.valueOf(i).contains("2") ||
String.valueOf(i).contains("3") ||
String.valueOf(i).contains("5") ||
String.valueOf(i).contains("6") ||
String.valueOf(i).contains("7") ||
String.valueOf(i).contains("8") ){}
else{
System.out.println(i);
}
}
This returns -
10000
10404
11449
14400
19044
40000
40401
44100
44944
90000
You can now manually pick the ordered number. I intentionally did this to keep the algorithm short but you can also pick up the number programmatically by converting it into a array.
The most basic solution I could think of:
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 38 39 |
|
that's my solution ,it's simple DFS :
def dfs(n,num): if n==5: if is_sqr(num) : s=str(num) if not not( s[1]>=s[0] and s[2]>=s[1] and s[3]>=s[2] \ and s[4]>=s[3] ): print num elif n==0: for i in range(1,4): dfs(n+1,a[i]) else: n+=1 for i in range(4): dell=num*10+a[i] dfs(n,dell)
Here's my python Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Output = 11449
java code:
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 |
|
output:
11449
Press any key to continue . . .
My C code for the problem. :)
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 |
|
Each no are square then squres no. In one digit is 1,4,&9 then it says its ordered no. Then we orderd 1, 4 & 9 in five digits its become a no 11449 the is a square of 107.. Thats the ans...
The most constricting condition is that the digits must each be square, so that means 1, 4, or 9 (or 0... but that would not work as this an ordered integer). I solved it by guessing that the answer would probably have all three and there are only a few such examples and I just used calculator to quickly spot the one with an integer square root. Hmmm what if you lack a calculator!? Then you first assume that the 5-digit number starts with 1. Then you know that the square root has to be between 100 (10.000) and 142 (root of 20,000 is 100 times root 2). And if you assume the number ends with 9, it the root has to end with 7. So try squaring 107, 117, 127, or 137. Happily the first one works. (If none of those had worked, and we would next have assumed the number starts with 4 and tried roots between 200 and 224 and so 207 and 217. The number cannot start with 9 since 99,999 is three squared times 11,111... but if 11,111 were a square then both 11,111 and 99,999 would be answers and there is only one answer. So if none of those had worked we would have known the number ends with 4 and been forced to go back and test 102, 108, 112, 118, 122, 128, 132, 138, 202, 208, 212, and 218)
why square root has to be between 100 and 142
I don't propose this as a "Solution" but here is how i did it:
The only viable digits are 1, 4 and 9.
5 digit square numbers start from the square of 100. They seem to end somewhere near the square of 300. Set up an column of numbers from 100 to 350 in excel. Calculate their square in the next column.
Now, soon as I did this, I saw the seventh number from the the top fits the bill. Answer is 11449, square of 107.
If it was not this apparent, what would I have done? Take out all the numbers that do not start with 1, 4 or 9.
The only viable number that starts with 9 is 99999. the square root is not a whole number. Take out all numbers starting with 9.
take out all numbers starting with 4 but have a lesser digit next to it. Then take out all numbers that have any digit except 4 or 9 as the second digit from left....and so on....
I am glad i didn't have to do this. Doesn't sound particularly interesting or elegant...
Is there any solution that does not involve such exhaustive checking?
You know, you forgot 44100, which is 210 squared. 0 is a square integer too.
Yes..right but 44100 is not an ordered number
Log in to reply
It is reverse ordered. I think @Michael Mendrin is correct.
Also, 0 is not a square integer because according to the clarifications:
... A square is a number obtained by multiplying a p o s i t i v e whole number by itself. ...
void main()
{ long int temp[220];
int i,j,a,m,n,o,p,f1,f2,f3,f4,f5;
a=1;
for(i=100;i<317;i++)
{
temp[a]=i*i;
a++;
}
for(j=1;j<218;j++)
{
m=temp[j]/10;
f1=temp[j]%10;
n=m/10;
f2=m%10;
o=n/10;
f3=n%10;
p=o/10;
f4=o%10;
f5=p;
if(f1==0 || f1==1 || f1==4 || f1== 9)
{
if(f2==0 || f2==1 || f2==4 || f2== 9)
{
if(f3==0 || f3==1 || f3==4 || f3== 9)
{
if(f4==0 || f4==1 || f4==4 || f4== 9)
{
if(f5==1 || f5==4 || f5== 9)
{
printf("Number is %lu \n",temp[j]);
}
}
}
}
}
}
getch();
}
Here is a Python 3.4.1 solution:
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 |
|
The program returns 11449 as the answer.
Why 144 is incorrect???
Log in to reply
the answer should be a 5-digit positive integer
here is a solution in haskell
import Data.List
import Data.Char
is_square :: Int -> Bool
is_square n = sq * sq == n
where sq = floor $ sqrt $ (fromIntegral n::Double)
is_elem_square :: [Int] -> Bool
is_elem_square [] = True
is_elem_square (x:xs) = is_square x && is_elem_square xs
is_ordered :: [Int] -> Bool
is_ordered [] = True
is_ordered (x:[]) = True
is_ordered (x:y:xs) = (x <= y) && is_ordered (y:xs)
check_all :: Int -> Bool
check_all x = is_square x && is_ordered list_x && is_elem_square list_x
where list_x = map digitToInt $ show x
solution = find check_all [10000..99999]
main = putStrLn $ show solution
Problem Loading...
Note Loading...
Set Loading...
Here is a rather inelegant, but one-line Mathematica solution:
The program returns {11449} .