611B - New Year and Old Property - CodeForces Solution


bitmasks brute force implementation *1300

Please click on ads to support us..

Python Code:

l=[]
for i in range(2,100):
    k=1
    while(2**i-1-k>0 and k<2**(i-1)):
        l.append((2**i)-1-k)
        k*=2

n,m=map(int, input().split())
nb=0
for j in l:
    if (j>=n) and (j<=m) :
        nb+=1
print(nb)

C++ Code:

#include<bits/stdc++.h>
#define int unsigned long long
#define fa(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define bp pop_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define Utaval  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
//int arr[200010][18];
vector<int>v;
void bina(int n,int ind){
    for(int i=0;i<=ind;i++){
        int numbery= n-(int)pow(2,i);
        v.pb(numbery);
    }
}
void solve(){
    int a,b,ans=0;
    cin>>a>>b;
    fa(i,0,v.size()){
        if(v[i]>=a && v[i]<=b)ans++;
    }
    cout<<ans<<endl;
}
signed main()
{
    Utaval;
    long long t=1;
    //cin>>t;
    for(int i=1;i<=64;i++){
        int ans = pow(2,i+1)-1;
        bina(ans,i-1);
    }
    sort(v.begin(),v.end());
    while(t--)
    solve();
}
		 	 	  	 	    	 			     	   		


Comments

Submit
0 Comments
More Questions

1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers
1174A - Ehab Fails to Be Thanos
1169A - Circle Metro