varun1425
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Assuming only the prime factors are to be 3,5,7::
for k = 1 P1 105
now go on multiplying with 3 then 5 and then 7.
k = 2 prod P2 = P1*3
k = 3 prod P3 = P1*5
k = 4 prod P4 = P1*7
k = 5 prod P5 = P2*3
k = 6 prod P6 = P2*5
k = 7 prod P7 = P2*7
Keep on growing the list to get Pk.
Also, Pk gives P(3k-1), P(3k) and P(3k+1)
So for any Kth multiple u need to generate only the factors needed for it.
This shud work:
int factor_3_5_7(int k)
{
if(k == 1)
return 3*5*7;
switch(k%3)
{
case 0:
return 5*factor_3_5_7(k/3);
case 1:
return 7*factor_3_5_7(k/3);
case 2:
return 3*factor_3_5_7((k/3) + 1);
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Since the question doesn't ask to find the duplicate:
- varun1425 July 24, 2008Find the XOR of the numbers in the array, and compare it with XOR of numbers 1 to N.
If same, no number is missing, else some number is repeated and some is missing.
Also, this solves the problem of overflow.