zoukankan      html  css  js  c++  java
  • Codeforces Round # 515 (div.3) A. Vova and Train

    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 44 and 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<iostream>
    using namespace std;
    typedef long long LL;
    int main()
    {
    	LL n,m,j,k,i,T,L,v,l,r,a,b;
    	cin>>T;
    	while (T--)
    	{
    		cin>>L>>v>>l>>r;
    	
    		LL sum=0,sum1=0;
    		sum = L/v;
    		
    		a = r/v;
    		if (l%v==0)
    		 b = l/v-1;
    		else
    		b = l/v;
    		sum1 = a-b;
    		
    		cout<<sum-sum1<<endl;
    	}
    	
    	return 0;
     } 
  • 相关阅读:
    Linux实战教学笔记30:Nginx反向代理与负载均衡应用实践
    Linux实战教学笔记29:MySQL数据库企业级应用实践
    Linux实战教学笔记28:企业级LNMP环境应用实践
    leetcode-Basic Calculator II
    java中 == 和 equals()方法的区别
    Java中为什么String不可变?
    关于Java的构造器和直接为成员变量赋值的区别
    Java修饰符的访问权限
    java深拷贝和浅拷贝
    leetcode-Length of Last Word
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451239.html
Copyright © 2011-2022 走看看