All Tracks Math Number Theory Basic Number Theory-2 Problem

Monk and Queries on coordinate plane
Tag(s):

Basic Number Theory-2, Easy-Medium, Math, Number Theory, approved

Problem
Editorial
Analytics

Monk is working on X−Y coordinate plane having N line segments indexed from 1 to N, and each one is represented with its 2 endpoints \([(x1,y1),(x2,y2)]\). He asks you Q queries on this X-Y plane.Each query contains an integer K.You have to tell the smallest index of line segment having atleast K lattice points.

If no such line segment exists print "-1".

Note: Lattice points are those points which have both x and y co-ordinate as an integer. Endpoints are also considered as lattice points.

Constraints:
\(1 \le N \le 10^5\)
\(-10^{10} \le x_1,y_1,x_2,y_2 \le 10^{10}\)
\(1 \le Q \le 10^5\)
\(1 \le K \le 10^9\)

Format of the input file:
First line : N
Next N lines : Four space separated integer x1,y1,x2,y2.
Next line : Q
Next Q lines : Integer K.

Format of the output file:
Print the final result to each query in a separate line.

SAMPLE INPUT
3
-26 37 -80 53
-15420 -74219 -16168 -79489
12503 23456 14971 13990
1
2
SAMPLE OUTPUT
1
Explanation

First line segment (with index=1) have 3 lattice points including the endpoints.

Hence the answer is 1.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

CodeMonk (Number Theory Part I)

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?