The Game of Chess-CodeWars 2013: Is my logic correct?

Im a newbie to codechef, And i have participated in CodeWars 2013 By BITS, Pilani today.
I was confused by the question ‘the game of chess’ (cdwrs05) [read it here][1]. But finally found a solution.
Can anybody please tell me wheather my logic is correct or not?

int main(){
	int t;
	unsigned long long r,logr=0,res,rem;
	t=readint();
	while(t--)
	{
		r=readint();
		rem=r;
		int count=0;
		while(rem>1)
		{
			logr=log(rem)/log(2);  //logr=log2 rem
			rem=rem-pow(2,logr);   //rem=rem-2^logr
			if(log(rem)>=0)
			count=count+logr-log(rem)/log(2); 
		}
		printf("%d\n",count);
	}
	return 0;
}

:frowning:
[1]: http://www.codechef.com/CODW2013/problems/CDWRS05