p, q, r | 16 Sep 2009

shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Possible solutions ::

45454565
82828202

0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
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
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I knew not many would attempt on this one. Congrats SP
naimish, SaswatPadhi likes this
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Thanx