Another optimization: Since the sum of the digits of n^2 is 45, n^2 is
divisible by 9. Thus, we need consider only n values that are
divisible by 3. Thus, the outer for-loop can be written

for( n = 31992 ; n < 99381 ; n+=3 )

Dave

On Feb 23, 7:02 pm, Dave <[email protected]> wrote:
> Try this:
>
>         int i,k,n;
>         long long j,nsq;
>         for( n = 31623 ; n < 100000 ; ++n )
>         {
>                 nsq = (long long)n * (long long)n;
>                 j = nsq;
>                 k = 0;
>                 for( i = 0 ; i < 10; ++i )
>                 {
>                         k |= (1 << (j % 10));
>                         j /= 10;
>                 }
>                 if( k == 01777 )
>                         printf("%i %lli\n",n,nsq);
>         }
>
> It finds 76 answers in the blink of an eye, the first being 32043^2
> and the last being 99066^2.
>
> Dave
>
> On Feb 22, 3:17 pm, bittu <[email protected]> wrote:
>
>
>
> > How to find a number of 10 digits (non repeated digits) which is a
> > perfect square? perfect square examples: 9 (3x3) 16 (4x4) 25(5x) etc.
> > Ten digit number example 1,234,567,890
>
> > Thanks & Regards
> > Shashank- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to