F: Flower Garden
https://open.kattis.com/problems/flowergarden
Last updated
https://open.kattis.com/problems/flowergarden
Last updated
First, construct a (this can be shared across all test cases) for the first 20,000 numbers.
Next, simulate Yraglac's walk from one flower to the next to determine the max number of flowers he can water before exceeding . To do this, keep track of Yraglac's current and total distance walked so far, and for each flower add to the total distance and update Yraglac's current position to . Break once the total distance exceeds .
Finally, count down from until hitting a prime number (using the prime sieve to check) or 0, and return that value.