#include <stdio.h>
#define DEBUG 0
int ab( long long int n ) {
#if DEBUG
printf("For n = %lld " , n);
#endif
int co = 0 , ce = 0;
int *a = &co;
int odd = 1;
while ( n != 0 ) {
if ( n & 1 ) {
if ( odd ) {
co ++;
}
else {
ce ++;
}
}
odd = 1 - odd;
n = n >> 1;
}
#if DEBUG
printf(" co = %d and ce = %d\n" , co , ce);
#endif
return co - ce;
}
int main ( int argc , char * argv[] ) {
int t;
scanf("%d" , &t);
while ( t-- ) {
long long int m,n,k;
scanf("%lld%lld%lld",&m,&n,&k);
long long int i = 0;
int count = 0;
for ( i = m ; i <= n ; i++ ) {
long long int d = ab(i);
if ( d == k || d == -k ) {
count ++;
}
}
printf("%d\n" , count);
}
return 0;
}
System Design for Beginners
A masterclass that helps early engineers and product managers become great at designing scalable systems.
180+ learners
Details →System Design Masterclass
A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.
1000+ learners
Details →Redis Internals
Learn internals of Redis by re-implementing some of the core features in Golang.
98+ learners
Details →