@Bhavesh: Check the squares of the integers from ceiling(sqrt(123456789)) to floor(sqrt(987654321)) to see which ones contain all nine nonzero digits. Since the sum of the nine nonzero digits is 45, a satisfactory square will be a multiple of 9, and therefore, we only need consider the squares of integers that are multiples of 3. Something like this should do the trick:
int i, j, k; for( i = 11112 ; i < 31426 ; i += 3 ) { j = i * i; k = 0; do { k |= 1 << (j % 10); j /= 10; } while( j > 0 ); if( k = 0x3FE ) // 11 1111 1110 in binary. printf("%i\n",i); } Dave On Jun 27, 11:01 pm, Bhavesh agrawal <agr.bhav...@gmail.com> wrote: > All the nine digits are arranged here so as to form four square numbers: > > 9 81 324 576 > > How would you put them together so as to form single smallest possible > square number and a single largest possible square number.. > > 139854276 and 923187456 are the answers given everywhere but how to proceed > this ?? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.