Interview Questions

There is long list of natural numbers.... .....

Microsoft Interview Questions and Answers


(Continued from previous question...)

280. There is long list of natural numbers.... .....

Question:
There is long list of natural numbers.
Remove every 2nd no from list in 1st pass
Remove every 3rd no from list in 2nd pass
Now find whether nth natural no will exist after p passes. n and p are inputs


maybe an answer:


bool willExist ( int X ,int p )
{
int k=2;

while( (k-1)<=p && k<=X )
{
if( ! (X % k ) )
return false;

X-=X/k;

k++ ;

}

return true;

}

(Continued on next question...)

Other Interview Questions