DWITE '10 R3 #1 - Integers along a line

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
DWITE Online Computer Programming Contest, December 2010, Problem 1

When talking about points on the Cartesian plane, most people tend to deal only with points with integer coordinates (i.e. points whose x and y coordinates are integers). Given a line segment with integer coordinates, you are curious about how many points on the line segment (other than the endpoints) have integer coordinates.

The input will contain 5 lines, each line having 4 integers -1000 \le A, B, X, Y \le 1000, where (A,B) describes one endpoint of a line, and (X,Y) describes another.

The output will contain 5 lines, each line containing the number of points along the line (not including the endpoints) that fall on the integer co-ordinates.

Sample Input

0 0 2 2
-1 -2 1 1

Sample Output


Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


There are no comments at the moment.