1. 程式人生 > >Codeforces Round #515 (Div. 3) A(思維)

Codeforces Round #515 (Div. 3) A(思維)

題意:找1~L之間 v 的倍數的個數,在區間[l,r]之間的不能算

思路:1到n之間v的倍數個數為n/v向下取整,因為是閉區間,所以區間裡v的倍數個數為r/v-(l-1)/v,l為什麼要減一?因為l-1/v是1到l-1中v的倍數個數。

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn=200005;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int n;
    cin>>n;
    while(n--)
    {
        int L,v,l,r;
        cin>>L>>v>>l>>r;
        cout<<L/v-(r/v-(l-1)/v)<<endl;
    }
    return 0;
}