20190216_G

Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute — at the point 2and so on).
There are lanterns on the path. They are placed at the points with coordinates divisible by v(i.e. the first lantern is at the point v, the second is at the point 2vand so on).
There is also exactly one standing train which occupies all the points from l
to rinclusive.Vova can see the lantern at the point p
if p is divisible by v and there is no standing train at this position (p∉[l;r]). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can’t see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to t
different conferences, so you should answer t independent queries.
Input
The first line of the input contains one integer t
(1≤t≤104) — the number of queries.
Then t
lines follow. The i-th line contains four integers Li,vi,li,ri (1≤L,v≤109, 1≤l≤r≤L) — destination point of the i -th path, the period of the lantern appearance and the segment occupied by the standing train.
Output
Print t
lines. The i-th line should contain one integer — the answer for the i
-th query.
Example
Input
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
Output
3
0
1134
0
题意:
有一组1~L的数字,你必须在其中找出含有v的倍数的个数,且v的倍数不包含在[l, r]区间内,问,有多少个这样的数字。
思路:
for循环是吧?!非常好,恭喜你T掉了。。。。
任何数字的组合,首先都不要暴力,潜在的规律往往尤为致命。

#include<stdio.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<math.h>
using namespace std ;
typedef long long ll;
#define maxn 10000005
#define INF 0x3f3f3f3f//将近int类型最大数的一半,而且乘2不会爆int

int main( )
{
   int t;
   cin >> t;
   for(int m=0; m<t; ++m)
   {
       int L, v, l, r, sum=0;
       scanf("%d %d %d %d", &L, &v, &l, &r);
       int c = L/v;
       int d = r/v - (l-1)/v;
       cout << c-d << '\n';
   }
    return 0;
}

是吧?!你瞅瞅。。。。(我的莽出来的规律。。。)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值