codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1066A.md (2443B)


      1 Source: https://codeforces.com/problemset/problem/1066/A
      2 
      3 A. Vova and Train
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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 $2$ and so on).
     22 
     23 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 $2v$ and so on).
     24 
     25 There is also exactly one standing train which occupies all the points from $l$ to $r$ inclusive.
     26 
     27 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 \not\in [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.
     28 
     29 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.
     30 
     31 Input
     32 
     33 The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of queries.
     34 
     35 Then $t$ lines follow. The $i$-th line contains four integers $L_i, v_i, l_i, r_i$ ($1 \le L, v \le 10^9$, $1 \le l \le r \le L$) — destination point of the $i$-th path, the period of the lantern appearance and the segment occupied by the standing train.
     36 
     37 Output
     38 
     39 Print $t$ lines. The $i$-th line should contain one integer — the answer for the $i$-th query.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 4  
     47 10 2 3 7  
     48 100 51 51 51  
     49 1234 1 100 199  
     50 1000000000 1 1 1000000000
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 3  
     57 0  
     58 1134  
     59 0
     60 ```
     61 
     62 Note
     63 
     64 For the first example query, the answer is $3$. There are lanterns at positions $2$, $4$, $6$, $8$ and $10$, but Vova didn't see the lanterns at positions $4$ and $6$ because of the standing train.
     65 
     66 For the second example query, the answer is $0$ because the only lantern is at the point $51$ and there is also a standing train at this point.
     67 
     68 For the third example query, the answer is $1134$ because there are $1234$ lanterns, but Vova didn't see the lanterns from the position $100$ to the position $199$ inclusive.
     69 
     70 For the fourth example query, the answer is $0$ because the standing train covers the whole path.