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)

#include <bits/stdc++.h>
using namespace std;

long long binary(long long bina){
    long long ans = 0;
    for (long long i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

int main() {
    long long n,count =0,ans = 0;
    string a;
    cin >> n >>a;
    string b = a;
    for (long long i = 0; i < n; i++){
        a = b;
        ans = 0;
        if(a.at(i) == '0')a.at(i) = '1';
        else if(a.at(i) == '1')a.at(i) = '0';
        bool flag = 0;
        for (long long i = 0; i < a.size(); i++){
            if(a.at(i) == '1'){
                flag = 0;
                break;
            }
            flag = 1;    
        }
        if(flag){
            cout << 0 << endl;
            continue;
        }
        long long x = stoi(a , 0, 2);
        while(1){
            for (long long i = 0; i < a.size(); i++){
                if(a.at(i) == '1')count ++;
            }
            x %= count;
            ans++;
            count = 0;
            if(x == 0)break;
            a = to_string(binary(x));
        }
        cout << ans << endl;
    }
}