题解 | #二叉树# 用递归加分治解决,左子树加右子树
二叉树
https://www.nowcoder.com/practice/f74c7506538b44399f2849eba2f050b5
#include <iostream> #include "cstdio" int pointNum(int m, int n) { if (2 * m + 1 <= n) return pointNum(2 * m, n) + pointNum(2 * m + 1, n) + 1; else if (2 * m <= n) return pointNum(2 * m, n) + 1; else return 1; } int main() { int n, m; while (scanf("%d %d", &m, &n) != EOF) { if (m == 0 && n == 0) break; printf("%d\n", pointNum(m, n)); } return 0; }