There are y ball with a bad one between them.
all the ball are the same look.
now, give you a balance, how many times do you need to pick out the bad one?
My resolution: need Ball(y) times to pick out the bad one.
#include <stdio.h>
#include <math.h>
int Ball(int y)
{
if(y <= 3) return 1;
return 1+Ball( y/3 * 3 == y ? y/3 : y/3 +1 );
}
int main()
{
int i = 0;
for(i = 2; i < 200; i++) {
printf("Ball(%3d)=%d \t", i, Ball(i));
if(i%5 == 0) puts("");
}
puts("");
return 0;
}