题目1113:二叉树

来源:互联网 发布:信贷软件 编辑:程序博客网 时间:2024/05/01 07:14
import java.io.IOException;import java.io.FileReader;import java.util.Scanner;class Main{public static final boolean DEBUG = false;public static void main(String[] args) throws IOException{Scanner cin;int m, n;if (DEBUG) {cin = new Scanner(new FileReader("d:\\OJ\\uva_in.txt"));} else {cin = new Scanner(System.in);}while (cin.hasNext()) {m = cin.nextInt();n = cin.nextInt();if (m == 0 && n == 0) break;int depth1 = (int)(Math.log(m) / Math.log(2)) + 1;int depth2 = (int)(Math.log(n) / Math.log(2)) + 1;int sum = 0, k = 1;for (int i = 0; i < depth2 - depth1; i++) {sum += k;k *= 2;}int start = m * k, end = start + k;if (end <= n) sum += k;else {for (int i = start; i <= n; i++) sum++;}System.out.println(sum);}}}

0 0