import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int l, r, m;
while (cin.hasNextInt()) {
l = cin.nextInt();
r = cin.nextInt();
m = cin.nextInt();
int c = 0;
//十进制数的范围
for (int i = l; i <= r; i++) {
//判断二进制中1的个数,并且记录次数
if (getCount(i) == m) {
c++;
}
}
//输出 判断如果c=0 c=-1,否则 c=c
System.out.println(c == 0 ? -1 : c);
}
}
private static int getCount(int n) {
int i = 0;
for (; n != 0; i++) {
n = n & (n - 1);
}
return i;
}
}
n&(n-1)n-1 应用
最新推荐文章于 2021-02-15 21:49:17 发布