Good Bye 2015 B. New Year and Old Property
阿新 • • 發佈:2017-07-06
位運算 problems 次方 num 推出 進制 and 運算 end
題目鏈接:http://codeforces.com/problemset/problem/611/B
解題思路:
直接暴力推出所有符合條件的。
由進制轉換可以知道,二進制只有1個0也就是十進制減去前面任意一個2的次方
然後腦殘一樣的用了位運算,死都無法表示64位,只能32位,還以為電腦出問題了。。換了pow秒過。。。
實現代碼:
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll m,n,i,j,a[100],b[10000],na,nb,c=0,num; a[0] = 1; for(i=1;i<63;i++){ a[i] = pow(2,i); a[i]+=a[i-1]; //cout<<a[i]<<endl; } b[0] = a[0]; cin>>m>>n; for(i=1;i<63;i++){ for(j=i-1;j>=0;j--){ num = pow(2,j); b[c++] = a[i] - num;//cout<<b[c-1]<<endl; } if(b[c-1]>=n){ break; } } if(m!=n){ for(i=0;i<c;i++){ if(b[i]>=m){ na=i; break; } } for(i=0;i<c;i++){ if(b[i]>n){ nb= i;break; } } cout<<nb-na<<endl; } else{ int flag = 0; for(i=0;i<c;i++){ if(b[i]==m) flag=1; //cout<<b[i]<<endl; } if(flag == 1) cout<<"1"<<endl; else cout<<"0"<<endl; } return 0; }
Good Bye 2015 B. New Year and Old Property