#P8594. 「KDOI-02」一个仇的复
「KDOI-02」一个仇的复
Background
Due to the OI contest format, subtasks are disabled for this problem. Some incorrect solutions may get high scores. Subtasks will be enabled after the contest.
"Have you heard about that incident? May they rest in peace."
"Huh? Look, what is that ring-shaped building ahead?"
"Let me compare it... Aha! This is their lair!"
"Destroy it, and avenge our fallen comrades!!!"
Dead cosmic rays point at fragile civilizations, ready to unleash their thunderous roar.
Problem Description
The aliens' space station has a ring-shaped structure. However, since the two ends of the ring are not connected, it can be approximated as a planar grid. Now, our ships have different types of ray weapons, each affecting a rectangle ( is a positive integer). Also, the weapon can be rotated clockwise or counterclockwise. The ray is extremely powerful: a single shot can annihilate everything within the affected area. However, if any part of the ray's affected area falls outside the target, it will keep extending to the end of the universe, greedily devouring everything along its path. The commander of course does not want to endanger innocent civilizations. He wants to know: among these weapons, if we choose types, how many different ways are there to destroy the aircraft.
[Formal statement]
You have infinitely many rectangles of size ( can be any positive integer) and a grid. Find the number of ways to select exactly rectangles (you may select identical rectangles) to tile the entire grid without overlap and without gaps. Rectangles may be rotated.
Input Format
Read input from standard input.
The input contains one line with two positive integers .
Output Format
Write output to standard output.
Output one line with one positive integer, the number of tiling ways modulo .
4 3
8
15 5
4015
3050 1314
670638639
19198114 4154
264122135
Hint
[Sample explanation]
- Sample 1 explanation:
There are solutions as shown in the figure below.

[Constraints]
For of the testdata, , .
| Test Point ID | Score | ||
|---|---|---|---|
Note: the Score column is the score of a single test point.
Translated by ChatGPT 5