請問是我哪裡出了問題?
#include<iostream>
using namespace std;
int main(){
int a, b;
while(cin >> a >> b){
int c = 0;
for(int i = 62; i >= 0; i--){
if((a & (1 << i)) == (b & (1 << i)))
c += (b & (1 << i));
else break;
}
cout << c << endl;
}
return 0;
}
請問是我哪裡出了問題?
#include
using namespace std;
int main(){
int a, b;
while(cin >> a >> b){
int c = 0;
for(int i = 62; i >= 0; i--){
if((a & (1 << i)) == (b & (1 << i)))
c += (b & (1 << i));
else break;
}
cout << c << endl;
}
return 0;
}
最大a,b<2^64,所以你用int裝不下,連while迴圈都進不去,要用unsigned long long