#P6429. [COCI 2008/2009 #1] JEZ

[COCI 2008/2009 #1] JEZ

Description

There is a rectangle of height rr and width cc, divided into r×cr \times c small 1×11 \times 1 rectangles.

Rows are numbered from top to bottom from 00 to r1r-1, and columns are numbered from left to right from 00 to c1c-1.

Each small rectangle has a color. If a small rectangle is at row xx and column yy, then:

  • If xy=x+yx\oplus y=x+y, this rectangle is gray.
  • Otherwise, it is white.

The lower-left figure shows the case r=c=10r=c=10:

Now someone walks kk steps along the path shown in the upper-right figure on this rectangle. Find how many gray cells they step on.

Input Format

The first line contains two integers rr and cc.

The second line contains one integer kk.

Output Format

Output one line containing the number of gray cells they step on.

10 10
6
5
3 5
11
8
10 10
100
51

Hint

Constraints

  • For 50%50\% of the testdata, k106k\le 10^6 is guaranteed.
  • For 100%100\% of the testdata, 1r,c1061\le r,c\le 10^6, 1kr×c1\le k\le r\times c, and the answer fits in a 3232-bit integer.

Notes:

This problem is translated from COCI2008-2009 CONTEST #1 JEZ. Translator: @菜鸟一只

Translated by ChatGPT 5