http://codeforces.com/contest/1066/problem/A

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.

代码:

#include <bits/stdc++.h>
using namespace std; int T;
int L, v, l, r;
int cnt; int main() {
scanf("%d", &T);
while(T --) {
cnt = 0;
scanf("%d%d%d%d", &L, &v, &l, &r);
cnt = L / v - r / v + (l - 1) / v;
printf("%d\n", cnt);
}
return 0;
}

  

CodeForces Round #515 Div.3 A. Vova and Train的更多相关文章

  1. Codeforces Round #515 (Div. 3)

    Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...

  2. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

  3. CodeForces Round #515 Div.3 B. Heaters

    http://codeforces.com/contest/1066/problem/B Vova's house is an array consisting of nn elements (yea ...

  4. A. Vova and Train ( Codeforces Round #515 (Div. 3) )

    题意:一条 L 长的路,一列车长在这条路的 l 到 r 之间,只有在 v 倍数时有灯,但是在 l 到 r 之间的灯是看不见的,问最大看见的灯的个数? 题解:L / v 表示总共的灯的个数, r / v ...

  5. Codeforces Round #515 (Div. 3) B. Heaters【 贪心 区间合并细节 】

    任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limi ...

  6. Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum

    E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...

  7. CodeForces Round #515 Div.3 D. Boxes Packing

    http://codeforces.com/contest/1066/problem/D Maksim has nn objects and mm boxes, each box has size e ...

  8. CodeForces Round #515 Div.3 C. Books Queries

    http://codeforces.com/contest/1066/problem/C You have got a shelf and want to put some books on it. ...

  9. CodeForces Round #515 DIv.3 F. Yet another 2D Walking

    http://codeforces.com/contest/1066/problem/F Maksim walks on a Cartesian plane. Initially, he stands ...

随机推荐

  1. Drupal 新建Modules

    最简单的模块包含了2个文件夹,它们放置于同一个文件夹下:包含模块信息的文件以.info为后缀名,而实现功能的文件则以.module结尾. 可以给模块一个友好的(human-readable)名字,但是 ...

  2. Webpack4 学习笔记五 图片解析、输出的文件划分目录

    前言 此内容是个人学习笔记,以便日后翻阅.非教程,如有错误还请指出 webpack打包图片和划分文件路径 使用图片的方式 通过 new Image() 在 css中设置 background-imag ...

  3. LeetCode426.Convert Binary Search Tree to Sorted Doubly Linked List

    题目 Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right point ...

  4. ofbiz研究

    近段时间,刚有有时间研究了下ofbiz ; 目前还是刚开始,后期会记录过程 有一起研究的没

  5. 记一次samba排错 Failed to start Samba SMB Daemon.

       记录一次服务出错排错的过程,很多新手出了点错不百度直接巴拉巴拉的问,一般老手根据经验可以给出一点建议,但是由于个体环境的差异并不适用,反而埋怨起来.这种真的无F**K可说,所以要培养自己的排错能 ...

  6. cacti和nagios监控web平台搭建

    在linux的运维中对服务器的监控,时刻了解服务器的状态是确保服务能够正常允许的条件,linux的服务监控平台有很多, cacti 下面对cacti(仙人掌),一种比较流行的开源监控软件做安装配置 具 ...

  7. The Extinction of Some Languages【一些语言的消失】

    The Extinction of Some Languages Languages have been coming and going for thousands of years, 语言的产生和 ...

  8. POJ:2739-Sum of Consecutive Prime Numbers(尺取)

    Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27853 Ac ...

  9. [Codeforces958E2]Guard Duty (medium)(区间DP)

    Description 题目链接 Solution 可以把题目转化一下模型,将间隔取出来,转化为N-1个数,限制不能取相邻两个数,求取K个数的最小价值 设DP[i][j]表示前i个数取j个最大价值(第 ...

  10. json loads/dumps

    json.dumps : dict转成str json.loads:str转成dict dict_ = {1: 2, 3: 4, "} print(type(dict_), dict_) # ...