完全二叉树 队列
二叉树
https://www.nowcoder.com/practice/f74c7506538b44399f2849eba2f050b5
#include <iostream> #include <bits/stdc++.h> #include <queue> using namespace std; int main() { int m,n; while(cin>>m>>n){ if(n==0){ continue; } int num=0; queue<int> q; if(m>n/2){ num = 1; } else{ int i; q.push(m); while(!q.empty()){ num++; i = q.front(); q.pop(); if(i*2<=n){ q.push(i*2); } if(i*2+1<=n){ q.push(i*2+1); } } } cout<<num<<endl; } }