A. Vova and Train

滴答滴答---题目链接

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vova plans to go to the conference by train. Initially, the train is at the point 11 and the destination point of the path is the point LL. The speed of the train is 11 length unit per minute (i.e. at the first minute the train is at the point 11, at the second minute — at the point 22 and so on).

There are lanterns on the path. They are placed at the points with coordinates divisible by vv (i.e. the first lantern is at the point vv, the second is at the point 2v2v and so on).

There is also exactly one standing train which occupies all the points from ll to rr inclusive.

Vova can see the lantern at the point pp if pp is divisible by vv and there is no standing train at this position (p∉[l;r]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 tt different conferences, so you should answer tt independent queries.

Input

The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of queries.

Then tt lines follow. The ii-th line contains four integers Li,vi,li,riLi,vi,li,ri (1≤L,v≤1091≤L,v≤109, 1≤l≤r≤L1≤l≤r≤L) — destination point of the ii-th path, the period of the lantern appearance and the segment occupied by the standing train.

Output

Print tt lines. The ii-th line should contain one integer — the answer for the ii-th query.

Example

input

Copy

4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000

output

Copy

3
0
1134
0

Note

For the first example query, the answer is 33. There are lanterns at positions 22, 44, 66, 88 and 1010, but Vova didn't see the lanterns at positions 44and 66 because of the standing train.

For the second example query, the answer is 00 because the only lantern is at the point 5151 and there is also a standing train at this point.

For the third example query, the answer is 11341134 because there are 12341234 lanterns, but Vova didn't see the lanterns from the position 100100 to the position 199199 inclusive.

For the fourth example query, the answer is 00 because the standing train covers the whole path.

题意描述:

VovaVova先生要乘火车去旅行,火车一开始位于11点,以每秒1个单位的速度向前行驶,最终到达LL处。(也就是说,火车在第1min1min时在11处,在2min2min时在2处)

铁路沿线挂着一些灯笼,这些灯笼的位于坐标是vv的倍数的地方,第一个灯笼位于vv处

同时,有另一列火车停在另一侧的轨道上,这列火车的左右端点位于ll和rr处

当VovaVova先生经过一个地点,这个地点既有灯笼,又没有被另一列火车挡住时,我们称VovaVova先生可以看到灯笼,现在,我们需要你求出一路上VovaVova先生能看到几盏灯笼。本题有多组数据。

输入输出格式:

输入格式:

第一行:一个整数t(1≤t≤10^4t(1≤t≤104),表示数据组数

下面tt行,每行4个整数L_iLi​,v_ivi​,l_ili​,r_iri​,(1≤L,v≤10^9,1≤l≤r≤L)(1≤L,v≤109,1≤l≤r≤L),各个字母的含义上文已经给出

输出格式:

tt行,每11个整数,表示VovaVova先生能看到的灯笼数

#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=1e6+1;
const int inf=0x3f33f3f;
int a[N];
int main()
{
    int m;
    cin>>m;
    while(m--)
    {
        long long int n,t,l,r;
        cin>>n>>t>>l>>r;
        l--;
        int ans=n/t;
        int l1=l/t;
        int r1=r/t;
        int p=r1-l1;
        ans=ans-p;
        cout<<ans<<endl;
    }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值