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: Runtime Error)

/*
 * 
 * 110101
 * po pierwszej zmianie wartosc spada na <= 2 * 10^5
 * log2(
 * 
 */
#include <bits/stdc++.h>

using namespace std;

#define LL long long 
#define ULL unsigned LL
#define LD long double 

const int N = 2e5 + 2137;
int f[N]; // value of f(i) for i <= 2*10^5

// return 2^x mod MOD
LL pot(LL x, LL mod) {
	if(x == 0)
		return 1;
	if(x%2) {
		return ((LL) 2 * pot(x-1, mod))%mod;
	}
	else {
		LL wx = pot(x/2, mod)%mod;
		return (wx*wx) % mod;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	f[0] = 0;
	for(int i=1; i<=2e5; i++) {
		int x = i;
		int w = 0;
		while(x) {
			x = x %__builtin_popcount(x);
			w++;
		}
		f[i] = w;
	}
	int n;
	cin>>n;
	string s;
	cin>>s;
	LL val[3];
	LL p = 0;
	for(int i=0; i<n; i++) {
		if(s[i] == '1')
			p++;
	}
	val[0] = val[1] = val[2] = 0;
	for(int i=0; i<n; i++) {
		if(p > 0)
			val[0] = (val[0]*(LL)2 + (s[i]=='1'?1:0))%(p-1);
		val[1] = (val[1]*(LL)2 + (s[i]=='1'?1:0))%p;
		val[2] = (val[2]*(LL)2 + (s[i]=='1'?1:0))%(p+1);
	}
	//cerr<<val[0]<<" "<<val[1]<<" "<<val[2]<<"\n\n\n";
	for(int i=0; i<n; i++) {
		if(s[i] == '1') {
			// -1
			// val[0]
			LL vx = val[0] - pot(n-i-1, p-1);
			//cerr<<"Wartosc vx = "<<vx<<"\n";
			vx%=((LL)(p-1));
			vx+=((LL)(p-1));
			vx%=((LL)(p-1));
			//cerr<<"Wartosc po modulacji, vx = "<<vx<<"\n";
			cout<<1+f[vx]<<"\n";
		}
		else {
			// +1
			// val[2]
			LL vx = val[2] + pot(n-i-1, p+1);
			//cerr<<"2 - Wartosc vx = "<<vx<<"\n";
			vx%=((LL)(p-1));
			vx+=((LL)(p-1));
			vx%=((LL)(p-1));
			//cerr<<"2 - Wartosc po modulacji, vx = "<<vx<<"\n";
			cout<<1+f[vx]<<"\n";
		}
		//cerr<<"\n\n";
	}
}