Inspired by Rajen Kapur

What is the smallest perfect square whose first four digits is 2016?

Note: Give the value of the perfect square.


The answer is 20164.

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.

3 solutions

Michael Mendrin
Apr 15, 2016

?.... um... 20160 = 141.986 \sqrt {20160}=141.986 , so try 142 2 = 20164 {142}^{2}=20164 ?

All right, this problem has generated numerous comments. Let's generalize a bit. Consider a number 2016 2016 followed by a a digits. Then we examine, for each a a , how many n n can there be. n n has to satisfy the following

2016 10 a < n < 2017 10 a \sqrt { 2016\cdot { 10 }^{ a } } <n<\sqrt { 2017\cdot { 10 }^{ a } }

which can be rewritten as

2016 < n 10 1 2 a < 2017 \sqrt { 2016 } <n\cdot { 10 }^{ -\frac { 1 }{ 2 } a }<\sqrt { 2017 }

or

44.899... < n 10 1 2 a < 44.911... 44.899...<n\cdot { 10 }^{ -\frac { 1 }{ 2 } a }<44.911...

which means for a square of an even number of digits starting with digits 2016 2016 , the unique answer is always 449 449 followed by zeroes. Likewise, the first expression can be rewritten as

( 2016 10 < n 10 1 2 ( a 1 ) < 2017 10 ) (\sqrt { 2016\cdot { 10 } } <n\cdot { 10 }^{ -\frac { 1 }{ 2 } \left( a-1 \right) }<\sqrt { 2017\cdot { 10 } } )

or

141.986... < n 10 1 2 ( a 1 ) < 142.021... 141.986...<n\cdot { 10 }^{ -\frac { 1 }{ 2 } \left(a-1\right) }<142.021...

which means for a square of an odd number of digits starting with 2016 2016 , the unique answer is always 142 142 followed by zeroes. See the following to see the uniqueness of 142 142 and 449 449

20164 = 142 2 20164={142}^{2}
201601 = 449 2 201601={449}^{2}
2016400 = 1420 2 2016400={1420}^{2}
20160100 = 4490 2 20160100={4490}^{2}


Those who only try 2016 44.89 \sqrt{2016} \approx 44.89\ldots will get a different answer.

Calvin Lin Staff - 5 years, 2 months ago

Log in to reply

I thought maybe I wasn't reading the question correctly. "First four digits is 2016", so since 2016 is not a perfect square, try a 5 digit number starting with 2016. Still, I did try a different approach for the more general problem. No need to go into details here now.

Michael Mendrin - 5 years, 2 months ago

Log in to reply

Yup, there is a very nice approach for the general problem, and we can also find a bound of the number of values to try.

Calvin Lin Staff - 5 years, 2 months ago

Log in to reply

@Calvin Lin How to find that bound?

Please give a hint.

Harsh Shrivastava - 5 years, 2 months ago

Log in to reply

@Harsh Shrivastava Think about how to approach the problem in a sensible way, and in particular why we seem to care about n \sqrt{n} and such.

If you're stuck, check out this problem .

Calvin Lin Staff - 5 years, 2 months ago

See expanded comments above. Is that what you're looking for?

Michael Mendrin - 5 years, 2 months ago
Mathias Haugsbø
Apr 17, 2016

I chosed to use a Javascript algorithm for this:

function findSmallestPerfectSquare() { var i = 1; while (true) { var tmp = i*i; if (tmp.toString().substring(0,4) === "2016") { return tmp; } else { i++; } } } var smallestPerfSquare = findSmallestPerfectSquare(); console.log(smallestPerfSquare);

Which will generate perfect squares and then check if the perfect squares' first 4 numbers is 2016. If not proceed to next perfect square. Returns: 20164 after 10ms (not fast I know)

What are various ways that we can speed up the program?

Calvin Lin Staff - 5 years, 1 month ago

Log in to reply

The mayor time issue is converting it to string and checking, but I don't know of any other method...

Other than that we could start with a higher number for example 44 which is the closest number under 2016. One could also check 44*44 manually and see that it has to be above 44 and check what sqrt(20160) (which is the next possible answer after 2016) and start with that number

I would love some suggestions to making it faster guys!

Mathias Haugsbø - 5 years, 1 month ago

Log in to reply

Check out this problem .

Sometimes, understanding the underlying mathematical structure can provide a simple approach :)

Calvin Lin Staff - 5 years, 1 month ago
Abhay Tiwari
Apr 16, 2016

well, a square of anumber has in its unit place a

  • 1 if the the number has 1 in its unit place. but

  • 4 if the number has 2 in its unit place. Thus, 20164 is the number.

How would you deal with the general case?

Calvin Lin Staff - 5 years, 2 months ago

Log in to reply

Sir, In general it will be the same. The unit digit is always between (0-9) for a particular number and for them we always have

1 in unit place of square for numbers with 1 in unit place

4 in unit place of square for numbers with 2 in unit place

9 in unit place of square for numbers with 3 in unit place

6 in unit place of square for numbers with 4 in unit place

5 in unit place of square for numbers with 5 in unit place

and so on till 9

and for square numbers if: n*n= {n}^{2}

and for square of (n+1) will be [{n}^{2}+ 2*n+1]

i.e. for eg., n=2, then square =4 and next number square = 4+2n+1=9, which the square of 3

Abhay Tiwari - 5 years, 2 months ago

Log in to reply

Say that the number we want the square to start off with is 3999.

Are you going to test 39990, 39991, 399994, 39999, 399901, 399904, 399904, etc?

Calvin Lin Staff - 5 years, 2 months ago

Log in to reply

@Calvin Lin Yes sir, I will start by testing the unit digit, because only they will be the square numbers, but there is no need to test all of them, simply by checking one number, we can get an oversight of the number we want to find.

Abhay Tiwari - 5 years, 2 months ago

@Calvin Lin Sir,Could you please post a note on how to solve this? I too thought what Abhay said was the only approach

Anirudh Chandramouli - 5 years, 2 months ago

Log in to reply

@Anirudh Chandramouli Here you go .

Calvin Lin Staff - 5 years, 2 months ago

Is there a theoretical way to do this?

Aditya Kumar - 5 years, 1 month ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...