2018-09-30 23:01:58 +01:00
---
id: 5900f5181000cf542c51002a
title: 'Problem 427: n-sequences'
2020-11-27 19:02:05 +01:00
challengeType: 5
2019-08-05 09:17:33 -07:00
forumTopicId: 302097
2021-01-13 03:31:00 +01:00
dashedName: problem-427-n-sequences
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2021-07-29 20:14:09 +02:00
A sequence of integers $S = \\{s_i\\}$ is called an $n$-sequence if it has $n$ elements and each element $s_i$ satisfies $1 ≤ s_i ≤ n$. Thus there are $n^n$ distinct $n$-sequences in total.
2020-11-27 19:02:05 +01:00
2021-07-29 20:14:09 +02:00
For example, the sequence $S = \\{1, 5, 5, 10, 7, 7, 7, 2, 3, 7\\}$ is a 10-sequence.
2018-09-30 23:01:58 +01:00
2021-07-29 20:14:09 +02:00
For any sequence $S$, let $L(S)$ be the length of the longest contiguous subsequence of $S$ with the same value. For example, for the given sequence $S$ above, $L(S) = 3$, because of the three consecutive 7's.
2018-09-30 23:01:58 +01:00
2021-07-29 20:14:09 +02:00
Let $f(n) = \sum L(S)$ for all $n$-sequences $S$.
2018-09-30 23:01:58 +01:00
2021-07-29 20:14:09 +02:00
For example, $f(3) = 45$, $f(7) = 1\\,403\\,689$ and $f(11) = 481\\,496\\,895\\,121$.
2018-09-30 23:01:58 +01:00
2021-07-29 20:14:09 +02:00
Find $f(7\\,500\\,000)\bmod 1\\,000\\,000\\,009$.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2021-07-29 20:14:09 +02:00
`nSequences()` should return `97138867` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
2021-07-29 20:14:09 +02:00
assert.strictEqual(nSequences(), 97138867);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
```js
2021-07-29 20:14:09 +02:00
function nSequences() {
2020-09-15 09:57:40 -07:00
2018-09-30 23:01:58 +01:00
return true;
}
2021-07-29 20:14:09 +02:00
nSequences();
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
// solution required
```