F - Infinite Sequence
Editorial
/


Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
{} からなる無限長の列 のうち、 次の条件を満たしているものは何通りあるでしょうか?
- 第 項から先はすべて同じ数である。つまり、 ならば を満たす。
- どの正の整数 に対しても、第 項の直後に並ぶ 個の項はすべて同じ数である。つまり、 ならば を満たす。
答えを で割ったあまりを求めてください。
制約
- は整数
入力
入力は以下の形式で標準入力から与えられる。
出力
条件を満たす数列の数を で割ったあまりを出力せよ。
入力例 1Copy
Copy
2
出力例 1Copy
Copy
4
以下の 通りがあります。
入力例 2Copy
Copy
654321
出力例 2Copy
Copy
968545283
Score : points
Problem Statement
How many infinite sequences consisting of {} satisfy the following conditions?
- The -th and subsequent elements are all equal. That is, if , .
- For every integer , the elements immediately following the -th element are all equal. That is, if , .
Find the count modulo .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print how many sequences satisfy the conditions, modulo .
Sample Input 1Copy
Copy
2
Sample Output 1Copy
Copy
4
The four sequences that satisfy the conditions are:
Sample Input 2Copy
Copy
654321
Sample Output 2Copy
Copy
968545283