4 kyu

Simple Fun #27: Rectangle Rotation

861 of 5,379myjinxin2015

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 Trained28882
Total Skips10906
Total Code Submissions34509
Total Times Completed5379
JavaScript Completions861
PHP Completions171
CoffeeScript Completions20
C# Completions401
Python Completions1721
Ruby Completions126
Java Completions525
Haskell Completions125
C++ Completions647
C Completions394
Elixir Completions30
Go Completions123
Dart Completions60
Elm Completions11
Erlang Completions15
Factor Completions9
Forth Completions7
Clojure Completions25
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 Completions154
TypeScript Completions146
Kotlin Completions90
Scala Completions55
Lua Completions51
Haxe Completions13
COBOL Completions8
Total Stars994
% of votes with a positive feedback rating92% of 852
Total "Very Satisfied" Votes741
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