import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static long m = 0, f = 0;
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int a = fs.nextInt();
int b = fs.nextInt();
long x[] = new long[32];
boolean y[] = new boolean[32];
int n = 0;
x[0] = 1;
x[1] = 2;
for (int i = 2; i < y.length; i++) {
x[i] = 2 * x[i - 1];
}
for (int i = 31; i >= 0; i--) {
if (a >= x[i]) {
a -= x[i];
y[i] = true;
n++;
}
}
if (n > b) {
int d = n - b;
for (int i = 0; i < y.length; i++) {
if (y[i] && d == 0) {
f = x[i];
break;
}
if (y[i] && d != 0) {
m += x[i];
d--;
}
}
System.out.println(f - m);
} else {
System.out.println(0);
}
}
public static class FastScanner {
private BufferedReader br;
private StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.valueOf(nextToken());
}
}
}
Java实现 洛谷 P1582 倒水
程序员文章站
2022-06-08 14:08:39
...
上一篇: 解决MySQL中float字段SUM()时出现一堆小数的问题_MySQL
下一篇: JS之深浅拷贝