4和6公共父节点为1
要求多组输入
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y;
while(cin>>x>>y)
{
while(x!=y)
{
if(x>y) x/=2;
if(x<y) y/=2;
}
cout<<x<<endl;
}
return 0;
}
4和6公共父节点为1
要求多组输入
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y;
while(cin>>x>>y)
{
while(x!=y)
{
if(x>y) x/=2;
if(x<y) y/=2;
}
cout<<x<<endl;
}
return 0;
}