0

I don't have Reviewing C++ By Alex Maurea book. But someone in facebook post a question from this book which is following

You can see the puzzle at page 542 problem 29.

Now I think the answer should be log2123456798. Am I right or I am tackling the question wrong way?

  • Your answer would be right if $k$ could be any real number, not just a positive integer (which I presume it must be; otherwise the problem would be trivial). – Peter Košinár Dec 20 '13 at 13:14

1 Answers1

1

You tackled in a wrong way. You must check the powers of 2 and find the smallest one, such that the last 9 digits are pairwise different and greater than 0.

By the way, the solution is

k=955

with ending digits

247315968

I found it with the following PARI-program

? k=1;gef=0;while(gef==0,k=k+1;n=Mod(2^k,10^9);u=component(n,2);x=vector(9);null =0;while(u>0,j=u-truncate(u/10)$*$10;if(j>0,x[j]=x[j]+1);if(j==0,null=1);u=truncat e(u/10));if((null==0)$*$(vecmin(x)>0),gef=1));print(k)

Peter
  • 84,454
  • As Peter Kosinar stated, k must be a natural number, otherwise the problem makes no sense. – Peter Dec 20 '13 at 13:18
  • Well I don't know the PARI language but can you give some nipticks/hint about the algorithm you used. It's christmas. :) – Anirban Nag 'tintinmj' Dec 20 '13 at 13:33
  • I calcaulated 2^k, took it modulo 10^9 to seperate the last 9 digits and counted the digits occuring with the array x. The digits are calculated by repeating division by 10. If the vector conatins no zeros and the digit 0 does not occur, the desired number is found. – Peter Dec 20 '13 at 13:35