Go4Expert

Go4Expert (http://www.go4expert.com/)
-   $1 Daily Competition (http://www.go4expert.com/contests/daily-competition/)
-   -   p, q, r | 16 Sep 2009 (http://www.go4expert.com/contests/p-q-r-16-sep-2009-t19457/)

shabbir 16Sep2009 18:58

p, q, r | 16 Sep 2009
 
X is positive integer of the form pqpqpqrq, such that (X-1) is a perfect square;

where p, q and r different digits from 0 to 9, with p being nonzero.

Determine X

SaswatPadhi 16Sep2009 19:16

Re: p, q, r | 16 Sep 2009
 
Possible solutions ::

45454565
82828202

:D

SaswatPadhi 16Sep2009 19:19

Re: p, q, r | 16 Sep 2009
 
Brute-force solution :

Code: CPP

#include <stdio.h>
#include <math.h>

int main()
{
    unsigned int p,q,r, Num, SNum;
    for(int p = 1; p < 10; ++p)
    {
        for(int q = 0; q < 10; ++q)
        {
            for(int r = 0; r < 10; ++r)
            {
                // pqpqpqrq
                Num = p*(10101000);
                Num += q*(1010101);
                Num += r*10;

                Num -= 1;

                SNum = floor(sqrt(Num));

                if(SNum * SNum == Num) {printf("p=%d q=%d r=%d\nX=%d\nX-1=%d\nsqrt(X-1)=%d\n\n", p,q,r,Num+1,Num,SNum);}
            }
        }
    }
    return 0;
}


Output ::

Code:

p=4 q=5 r=6
X=45454565
X-1=45454564
sqrt(X-1)=6742

p=8 q=2 r=0
X=82828202
X-1=82828201
sqrt(X-1)=9101

Process returned 0 (0x0)  execution time : 0.031 s


shabbir 17Sep2009 13:21

Re: p, q, r | 16 Sep 2009
 
I knew not many would attempt on this one. Congrats SP

SaswatPadhi 17Sep2009 18:26

Re: p, q, r | 16 Sep 2009
 
Thanx :D


All times are GMT +5.5. The time now is 05:51.