cswork / OA打开练习工作台

UberOA #27

Count L-Shaped Plots

估计中等可在线判题

考点(AI 标注)哈希计数位运算

In a grid of n rows and m columns, cell (i,j) holds a flower if and only if ((i+j×magic) mod mod) mod 2=1, with coordinates starting from 0. Count the L shapes formed by three distinct flower cells: one cell shares a row with the second and a column with the third, and they need not be adjacent. Each set of three cells is counted only once.

This site's standard input/output is stated explicitly.

输入格式

One line: n m magic mod; 1≤n,m≤1000, 1≤magic,mod≤10⁶.

输出格式

Output one integer answer.

样例 1

输入:

4 3 2 2

输出:

12

样例 2

输入:

2 2 1 2

输出:

0

样例 3

输入:

3 3 1 3

输出:

0

样例说明

Example 1: rows 2 and 4 each have 3 flowers. Each of the 6 corner cells can pick the other 2 flowers in its row and the other 1 in its column, for 12 groups in total. Example 2: there are only two flowers, which cannot form a triple, so the output is 0. Example 3: the three flowers are at (0,1), (1,0), and (2,2), with only one flower in each row and column, so the output is 0.