2018-09-30 23:01:58 +01:00
---
id: 5900f5081000cf542c510019
title: 'Problem 411: Uphill paths'
2020-11-27 19:02:05 +01:00
challengeType: 5
2019-08-05 09:17:33 -07:00
forumTopicId: 302080
2021-01-13 03:31:00 +01:00
dashedName: problem-411-uphill-paths
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
2021-07-29 19:48:24 +02:00
Let $n$ be a positive integer. Suppose there are stations at the coordinates $(x, y) = (2^i\bmod n, 3^i\bmod n)$ for $0 ≤ i ≤ 2n$. We will consider stations with the same coordinates as the same station.
2018-09-30 23:01:58 +01:00
2021-07-29 19:48:24 +02:00
We wish to form a path from (0, 0) to ($n$, $n$) such that the $x$ and $y$ coordinates never decrease.
2018-09-30 23:01:58 +01:00
2021-07-29 19:48:24 +02:00
Let $S(n)$ be the maximum number of stations such a path can pass through.
2018-09-30 23:01:58 +01:00
2021-07-29 19:48:24 +02:00
For example, if $n = 22$, there are 11 distinct stations, and a valid path can pass through at most 5 stations. Therefore, $S(22) = 5$. The case is illustrated below, with an example of an optimal path:
2018-09-30 23:01:58 +01:00
2021-07-29 19:48:24 +02:00
<img class="img-responsive center-block" alt="valid path passing through 5 stations, for n = 22, with 11 distinct stations" src="https://cdn.freecodecamp.org/curriculum/project-euler/uphill-paths.png" style="background-color: white; padding: 10px;">
It can also be verified that $S(123) = 14$ and $S(10\\,000) = 48$.
Find $\sum S(k^5)$ for $1 ≤ k ≤ 30$.
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 19:48:24 +02:00
`uphillPaths()` should return `9936352` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
2021-07-29 19:48:24 +02:00
assert.strictEqual(uphillPaths(), 9936352);
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 19:48:24 +02:00
function uphillPaths() {
2020-09-15 09:57:40 -07:00
2018-09-30 23:01:58 +01:00
return true;
}
2021-07-29 19:48:24 +02:00
uphillPaths();
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
```