Guest Posted December 28, 2011 Report Share Posted December 28, 2011 not a difficult one but interesting : there is a 4 digit no. 'n' such that last 4 digits of n2 are actually the no. 'n' Find n.... Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 28, 2011 Report Share Posted December 28, 2011 n = 9376 n2 =87909376 Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 28, 2011 Report Share Posted December 28, 2011 (edited) N=9376 N2=87909376 Must love computers I went further and found the same for 5, 6, 7, 8 and 9 digit numbers as well.4 N=9376 N2=879093765 N=83647 N2=21474836476 N=483647 N2=21474836477 N=7483647 N2=21474836478 N=47483647 N2=21474836479 N=147483647 N2=2147483647 Here is the java code I wrote to find it, took about 1 min public static void main(String[] args) { for (int n=1000; n<= 999999999; n++) { int n2 = (int) Math.pow(n, 2); String ns = String.valueOf(n); String n2s = String.valueOf(n2); if (n2s.lastIndexOf(String.valueOf(n)) == (n2s.length() - ns.length() ) ) { System.out.println(ns.length()+" N="+n+" N2="+n2); } } } Edited December 28, 2011 by bendigi Quote Link to comment Share on other sites More sharing options...
0 CaptainEd Posted December 28, 2011 Report Share Posted December 28, 2011 Bendigi, why do items 5-9 all have the same square? Also, my Excel shows a different square for 83647, 6996820609 rather than 2147483647 Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 28, 2011 Report Share Posted December 28, 2011 (edited) You are right Captain Ed, I had a booboo in my code, I forgot about int's max, changed it to long type and there is the latest results It's interesting when n is 6, 7 and 8, there are actually two answers for this puzzle. 4 N=9376 N2=879093765 N=90625 N2=82128906256 N=109376 N2=119631093766 N=890625 N2=7932128906257 N=2890625 N2=83557128906257 N=7109376 N2=505432271093768 N=12890625 N2=1661682128906258 N=87109376 N2=75880433871093769 N=787109376 N2=619541169787109376 And the latest Code: public static void main(String[] args) { for (int n=1000; n<= 999999999; n++) { long n2 = (long) Math.pow(n, 2); String ns = String.valueOf(n); String n2s = String.valueOf(n2); if (n2s.lastIndexOf(ns) == (n2s.length() - ns.length() ) ) { System.out.println(ns.length()+" N="+n+" N2="+n2); } } } BTW, I am not able to edit my original post more than 3 times ? Edited December 28, 2011 by bendigi Quote Link to comment Share on other sites More sharing options...
0 CaptainEd Posted December 28, 2011 Report Share Posted December 28, 2011 Ah! Those look more plausible. I think the editing threshold is based on amount of time since first creation, rather than attempt-based, but I'm not sure. I make a lot of mistakes in my proofs, etc., and I so I have run into the editing threshold several times. Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 28, 2011 Report Share Posted December 28, 2011 (edited) Yeah!! 9376 is the answer!! I made a java program to find it. Check it out:- int i=1000,n=0,a; for(i=1000;i<=9999;i++) { n=i*i; a=n/10000; a=a*10000; a=n-a; if(a==i) { System.out.println(i); System.exit(0); } } Edited December 28, 2011 by VampBrain Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 28, 2011 Report Share Posted December 28, 2011 <p>Im curious is there a methodology to find this without just brute forcing it?</p> Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 28, 2011 Report Share Posted December 28, 2011 Last digit can be a. 0 b. 1 c. 5 d. 6 We will take them one by one. a) If we have 0 at last, then even if we have anything before it, it will keep on giving 00 at last, again if we have 00 at last it will keep giving 0000 at last and so on. So, ruling out 0 as last digit. b) If we have 1 at last, we cant have anything before tha so that its square gives same last 2 digit. i.e: 11*11 = 121, 21*21 =441 and so on. So, ruling out 1 also. c) If we have 5 as last digit, we have only 25*25 = 625(i.e: Last 2 digits are same). Going ahead, we can find that (x00 + 25) * (x00 + 25) = yz0000 + 50 * x00 + 625 , so we can have x=6. Now, 625*625 = 390625 Going forward, (x000 + 625) * (x000 + 625) = yz000000 + 1250 * x000 + 390625, we cant have 0 at 4th place, so this option is ruled out. d) 6 as last digit (x0 + 6) * (x0 + 6) = yz00 + 36 * x0 + 36. We can find out that only x=7 satisfies the condition for last 2 digit to be same. 76 * 76 = 5776 Similarly, we can find that digit at hundreth place should be, 3( 376 * 376 = 141376) and digit at thousanth place should be 9 (9376 * 9376 = 87909376) 9376 : 87909376 Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 28, 2011 Report Share Posted December 28, 2011 Just wanted to add a code example for a brute force solution this using python for i in range(1000,9999): if str(i) == str(i*i)[-4:]: print i, i*i Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 29, 2011 Report Share Posted December 29, 2011 (edited) n2 ends in n and n is 4 digit number. This means that, n2 = 10000x + n n(n-1) = 10000x Now, either n or n-1 must be a multiple of 54 (625) and the other number must be a multiple of 24 (16) Now take all 4 digit multiples of 625 that are odd. there are only 7. Now consider numbers +1 of these numbers and divide them by 16. You don't need to consider -1 of these numbers as they would end in 4 and the square of this number would end in 6. Of these 7 numbers, there is only one that is divisible by 16. Not surprisingly it is 9376. So, this is the number you are looking for. You can use this method for any number of digits of "n". Edited December 29, 2011 by DeeGee Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 29, 2011 Report Share Posted December 29, 2011 Could not edit the above post but there is a correction to be made. You need to check the the -1 numbers for divisibility as well. Although it does not make a difference for 4 digit numbers, for higher digit numbers it will be needed. Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 31, 2011 Report Share Posted December 31, 2011 (edited) what about n = 0001 n^2 = 0001 trying to find a result in binary is an idea... im feelin lazy.....hence my answer :-p Edited December 31, 2011 by RHITMAN07 Quote Link to comment Share on other sites More sharing options...
0 Guest Posted December 31, 2011 Report Share Posted December 31, 2011 (edited) <p>Im curious is there a methodology to find this without just brute forcing it?</p> Edited December 31, 2011 by RHITMAN07 Quote Link to comment Share on other sites More sharing options...
Question
Guest
not a difficult one but interesting :
there is a 4 digit no. 'n' such that last 4 digits of n2 are actually the no. 'n'
Find n....
Link to comment
Share on other sites
13 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.