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;
}

猜你喜欢

转载自blog.csdn.net/Dilly__dally/article/details/83063754