直接套的以前代码
幸好10000的二进制不是很大
#include<bits/stdc++.h>
using namespace std ;
long long mpow(int n , int p){
long long x = 1 ;
for(int i = 1 ; i <= p ; i++){
x *= n ;
}
return x ;
}
long long TtB(int Tx){
long long Bx=0;
int p = -1 ;
while(Tx){
p++;
Bx+=Tx%2*mpow(10,p);
Tx/=2;
}
return Bx ;
}
bool ispalindromic (long long x){//是不是回文數,沒有負數
long long s = 0 ;
long long n = x ;
while (n){
s = s * 10 + n % 10 ;
n /= 10 ;
}
if ( s == x ){
return true ;
} else {
return false ;
}
}
int B_palindromics (int L , int R ){//L和R之間的二进制回文數,经修改
int sum = 0 ;
for(int i = L ; i <= R ; i++ ){
if (ispalindromic(TtB(i))){
sum++;
}
}
return sum ;
}
int main(){
int n ;
cin >> n ;
cout << B_palindromics(1,n);
}