Problem:
Score : 100 points

Problem Statement

How many multiples of d are there among the integers between L and R (inclusive)?

Constraints

All values in input are integers.

1 \leq L \leq R \leq 100

1 \leq d \leq 100

Input

Input is given from Standard Input in the following format:

L R d

Output

Print the number of multiples of d among the integers between L and R (inclusive).

Sample Input 1

5 10 2

Sample Output 1

3

Among the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.

Sample Input 2

6 20 7

Sample Output 2

2

Among the integers between 6 and 20, there are two multiples of 7: 7 and 14.

Sample Input 3

1 100 1

Sample Output 3

100

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

int mp[400005];

signed main(){
    FASTER;
    int n;cin>>n;
    string s;cin>>s;
    
    for(int i=0;i<400005;i++){
        int tmp=i;
        int ans=0;
        while(tmp){
            tmp=tmp%__builtin_popcountll(tmp);
            ans++;
        }
        mp[i]=ans;
    }
    
    int cnt=0;
    for(char c:s)cnt+=(c=='1');
    
    int Pp1=0,Pm1=0,cur1 = 1,cur2 = 1;
    for(int i=n-1,id=0;i>=0;i--,id++){
        if(s[i]=='1'){
            Pp1=(Pp1+cur2 % (cnt + 1))%(cnt+1);
            if(cnt>=2)Pm1=(Pm1+cur1 % (cnt - 1))%(cnt-1);
        }
        if(cnt > 1){
            cur1 *= 2;
            cur1 %= (cnt - 1); 
        } 
        cur2 *= 2;
        cur2 %= (cnt + 1);
    }
    
    vi cp1mod(n+n,1);
    for(int i=1;i<2*n;i++){
        cp1mod[i]=cp1mod[i-1]*2%(cnt+1);
    }
    vi cm1mod(n+n,1);
    for(int i=1;i<2*n && cnt>1;i++){
        cm1mod[i]=cm1mod[i-1]*2%(cnt-1);
    }
    
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            int rem=(Pp1+cp1mod[n-i-1])%(cnt+1);
            int cntt=1+mp[rem];
            cout<<cntt<<"\n";
        }else{
            if(cnt==1){
                cout<<0<<"\n";
            }else{
                int rem=(Pm1-cm1mod[n-i-1]+cnt-1)%(cnt-1);
                int cntt=1+mp[rem];
                cout<<cntt<<"\n";
            }
        }
    }
    
}