4 kyu

Simple Fun #27: Rectangle Rotation

868 of 5,474myjinxin2015

Description:

Task

A rectangle with sides equal to even integers a and b is drawn on the Cartesian plane. Its center (the intersection point of its diagonals) coincides with the point (0, 0), but the sides of the rectangle are not parallel to the axes; instead, they are forming 45 degree angles with the axes.

How many points with integer coordinates are located inside the given rectangle (including on its sides)?

Example

For a = 6 and b = 4, the output should be 23

The following picture illustrates the example, and the 23 points are marked green.

Input/Output

  • [input] integer a

    A positive even integer.

    Constraints: 2 ≤ a ≤ 10000.

  • [input] integer b

    A positive even integer.

    Constraints: 2 ≤ b ≤ 10000.

  • [output] an integer

    The number of inner points with integer coordinates.

Puzzles

Stats:

CreatedJan 24, 2017
PublishedJan 24, 2017
Warriors Trained29342
Total Skips11079
Total Code Submissions34919
Total Times Completed5474
JavaScript Completions868
PHP Completions172
CoffeeScript Completions20
C# Completions405
Python Completions1740
Ruby Completions126
Java Completions527
Haskell Completions126
C++ Completions685
C Completions400
Elixir Completions30
Go Completions128
Dart Completions63
Elm Completions11
Erlang Completions15
Factor Completions9
Forth Completions7
Clojure Completions26
Crystal Completions16
F# Completions21
Julia Completions29
NASM Completions13
Prolog Completions9
PureScript Completions8
R Completions48
Racket Completions18
CFML Completions7
Fortran Completions10
Groovy Completions13
Nim Completions12
Objective-C Completions12
Reason Completions4
Rust Completions157
TypeScript Completions152
Kotlin Completions92
Scala Completions55
Lua Completions51
Haxe Completions13
COBOL Completions8
Total Stars1001
% of votes with a positive feedback rating92% of 857
Total "Very Satisfied" Votes746
Total "Somewhat Satisfied" Votes88
Total "Not Satisfied" Votes23
Total Rank Assessments7
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • smile67 Avatar
  • St3f4n Avatar
  • kazk Avatar
  • docgunthrop Avatar
  • JohanWiltink Avatar
  • JorgeVS Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • clcraig Avatar
  • monadius Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • sid114 Avatar
Ad