Design an algorithm to find the kth number divisible by only 3 or 5 or 7 i.e the only factors of these numbers should be 3,5 and 7.
int foo(int k)
{
int min=3*5*7;
minheap h;
h.push(val);
int idx=0;
while(k < idx)
{
min=h.pop();
k++;
h.update();
h.push(min*3);
h.push(min*5);
h.push(min*7);
}
return min;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment