Skipping stones solution

 avatar
unknown
c_cpp
6 months ago
480 B
3
Indexable
#include<bits/stdc++.h>
using namespace std;

int sol(int l, int u, int g){
    return ((u / g) - (l / g) + ((l % g) == 0));
}
int main() {
    int t;
    cin >> t;
    while(t--){
        int x, a, s, l, u;
        cin >> x >> a >> s >> l >> u;
        int g = gcd(a, s);
        if(x < l) cout << sol(l - x, u - x, g) << endl;
        else if(u < x) cout << sol(x - u, x - l, g) << endl;
        else cout << sol(1, x - l, g) + sol(0, u - x, g) << endl;
    }
}
Editor is loading...
Leave a Comment