题解 | #二叉树#
二叉树
https://www.nowcoder.com/practice/5b80ab166efa4551844657603227caeb
#include <stdio.h> int fun(int a, int b) { if (a == 1 || b == 1) { return 1; } else if (a == b) { return a; } else if (a > b) { return (a % 2 == 0) ? fun(a / 2, b) : fun((a - 1) / 2, b); } else { return (b % 2 == 0) ? fun(a, b / 2) : fun(a, (b - 1) / 2); } return 0; } int main() { int a, b; while (scanf("%d %d", &a, &b) != EOF) { printf("%d\n", fun(a,b)); } return 0; }