問題一覧 > 通常問題

No.613 Solitude by the window

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 24
作問者 : 夕叢霧香(ゆうむらきりか) / テスター : uwi
お気に入りにしたユーザー ProblemId : 2019 / 自分の提出
問題文最終更新日: 2026-06-25 08:26:46
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
Advent Calendar Contest 2017 (順位表) の他の問題:

Problem Statement

Initially, there are 2 stones. Every second, each of these stones simultaneously splits into (the number of stones at that moment + 4) stones. For example, after 1 second from the start there are $2 \times (2 + 4) = 12$ stones, and after 1 more second there are $12 \times (12 + 4) = 192$ stones. Find the number of stones after $N$ seconds, modulo $\text{mod}~M$ ($M$ is a prime).

Input

N M

$N$ is an integer, $1\le N \le 10^{18}$.
$M$ is a prime, $2\le M \le 1100000000=1.1\times 10^9$.

Output

Print a newline at the end.

Sample

Sample 1
Input
2 10007
Output
192

Sample 2
Input
100000000 5
Output
2

Letting $a_n$ be the number of stones after $n$ seconds, $a_n \equiv 2 \pmod 5$ holds for every integer $n$ that is at least 0.

Sample 3
Input
1000000000000000000 1000000007
Output
688982865

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