#P2332. [SCOI2006] 数字立方体

[SCOI2006] 数字立方体

Description

A cube is partitioned into n×n×nn\times n\times n unit cubes, with coordinates denoted by (X,Y,Z)(X, Y, Z) where 1X,Y,Zn1\le X, Y, Z\le n. Each unit cube contains an integer whose absolute value does not exceed 10910^9. Count how many subcubes have the sum of all numbers being a multiple of mm. A subcube is the set of all unit cubes satisfying x1Xx2x_1\le X\le x_2, y1Yy2y_1\le Y\le y_2, z1Zz2z_1\le Z\le z_2, where 1x1,x2,y1,y2,z1,z2n1\le x_1, x_2, y_1, y_2, z_1, z_2\le n.

Input Format

The first line contains two integers n,mn, m, representing the edge length of the cube and the positive integer divisor.

The following n×nn\times n lines each contain nn integers. First come the nn unit cubes with X=1,Y=1X=1, Y=1 (i.e., Z=1,2,,nZ=1,2,\dots,n), then X=1,Y=2X=1, Y=2, …, and finally X=n,Y=n1X=n, Y=n-1 and X=n,Y=nX=n, Y=n, for a total of n3n^3 integers.

Output Format

Output a single number: the number of subcubes whose sum of integers is a multiple of mm.

2 5
1 2
3 4
5 6
7 8

5

Hint

Constraints and Conventions

  • 30%30\% of the testdata satisfies 1n101\le n\le 10.
  • 100%100\% of the testdata satisfies 1n401\le n\le 40.

For all testdata, 1m1061\le m\le 10^6.

Translated by ChatGPT 5