Monk and Queries on coordinate plane
Tag(s):

## Easy-Medium, Mathematics, Number Theory, 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.

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: Bash, 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, TypeScript, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in Challenge Name

CodeMonk (Number Theory Part I)

OTHER PROBLEMS OF THIS CHALLENGE
• Math > Number Theory
• Math > Number Theory
• Math > Number Theory
• Math > Number Theory
Уведомления

?