# Task
 Imagine a white rectangular grid of `n` rows and `m` columns divided into two parts by a diagonal line running from the upper left to the lower right corner. Now let's paint the grid in two colors according to the following rules:
```
 A cell is painted black if it has at least one point in common with the diagonal;
Otherwise, a cell is painted white.
```
 Count the number of cells painted black.

# Example

 For n = 3 and m = 4, the output should be `6`

 There are 6 cells that have at least one common point with the diagonal and therefore are painted black.

 For n = 3 and m = 3, the output should be `7`

 7 cells have at least one common point with the diagonal and are painted black.

# Input/Output

 - `[input]` integer `n`

   The number of rows.

   Constraints: 1 ≤ n ≤ 10000.

 - `[input]` integer `m`

   The number of columns.

   Constraints: 1 ≤ m ≤ 10000.

 - `[output]` an integer

   The number of black cells.

Difficulty: introductory

Starter code:

def count_black_cells(h, w):
	

Solutions:
from fractions import gcd
def count_black_cells(h, w):
    return (h + w) -2 + gcd(h,w)

from math import floor, ceil

def count_black_cells(h, w):
    if w < h: h, w = w, h
    diag, step = -2, w / h
    for i in range(h):
        left = floor(i * step - 1e-9)
        right = ceil((i+1) * step + 1e-9)
        diag += right - left
    return diag

from math import gcd
def count_black_cells(h, w):
    return h + w + gcd(h, w) - 2

import math

def count_black_cells(h, w):
    return h+w+math.gcd(h,w)-2

from fractions import gcd

def count_black_cells(h, w):
    return h + w + gcd(h, w) - 2

import math
def count_black_cells(h, w):
  r,y,up,t=0,1,0,None
  while(y<=w):
    t=math.ceil(h*y/w)
    r+=t-up+(1 if y!=w and h*y/w==t else 0)
    y+=1
    up=t-1
  return r

from fractions import Fraction as F
from math import ceil, floor

def count_black_cells(h, w):
    total = 0
    r = F(h, w)
    last_y = 0
    for x in range(w + 1):
        y = x * r
        total += ceil(y) - floor(last_y)
        if 0 < x < w and y == int(y):
            total += 2
        last_y = y
    return total

from math import gcd

def count_black_cells(h, w):
    return w + h + gcd(h, w) - 2

def count_black_cells(h, w):
    if h==w:
        return 3*h-2
    r=0
    x1=0
    for i in range(h):
        x2=w*(i+1)/h
        r+=(int(x2)+1)-int(x1)
        if int(x1)==x1 and x1!=0:
            r+=1
        elif i==h-1:
            r-=1
        x1=x2
    return r