問題一覧 > 通常問題

No.377 Background Pattern

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 35
作問者 : EmKjp / テスター : 紙ぺーぱー
お気に入りにしたユーザー ProblemId : 561 / 自分の提出
問題文最終更新日: 2026-06-25 15:51:01
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 138 (順位表) の他の問題:

Problem Statement

We have decided to create an image of height $H$ and width $W$, and to make an infinitely extending background pattern by repeatedly placing it vertically and horizontally.
There are $K$ colors, numbered from $0$ to $K-1$, and each of the $W \times H$ pixels of the image is assigned one of the $K$ colors.

For example, the background pattern obtained by repeatedly placing the image of height 2 and width 3

123
456
is as follows.
123123123123123123
456456456456456456
123123123123123123
456456456456456456
123123123123123123
456456456456456456
(無限に同じパターンが続きます)
Write a program that outputs the number of background patterns that can be generated from images of height $H$ and width $W$, modulo $10^9 + 7$.
Here, background patterns that become exactly identical under a translation are considered the same.
For example, the background patterns obtained from the following 6 images are all treated as the same.
123 231 312 456 564 645
456 564 645 123 231 312

Input

H W K

$1 \le H \le 10^9 $
$1 \le W \le 10^9 $
$1 \le K \le 10^9 $

Output

Output the number of background patterns that can be generated, modulo $10^9 + 7$. Print a newline at the end.

Sample

Sample 1
Input
2 2 1
Output
1

Since only one color can be used, the only background image that can be made is one filled entirely with that single color.

Sample 2
Input
2 2 2
Output
7

The following 7 background patterns can be generated.

111111 101010 111111 101010 111111 101010 000000
111111 010101 010101 000000 000000 101010 000000
111111 101010 111111 101010 111111 101010 000000
111111 010101 010101 000000 000000 101010 000000
111111 101010 111111 101010 111111 101010 000000

Sample 3
Input
1 3 3
Output
11

The following 11 background patterns can be generated.

000000 001001 011011 111111 112112 122122 222222 220220 200200 120120 021021
000000 001001 011011 111111 112112 122122 222222 220220 200200 120120 021021
000000 001001 011011 111111 112112 122122 222222 220220 200200 120120 021021
000000 001001 011011 111111 112112 122122 222222 220220 200200 120120 021021
000000 001001 011011 111111 112112 122122 222222 220220 200200 120120 021021

Sample 4
Input
5 7 10
Output
878302877

Sample 5
Input
111 222 333
Output
91610936

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。