i recently solved this problem: https://mirror.codeforces.com/contest/1097/problem/B,
I know that it's an easy problem with a brute-force solution but, I'm curious how to solve it for $$${1 <= N <= 10^5}$$$, I'd appreciate your help, thanks in advance.
It's actually possible using dynamic programming, where the state is number of turns used and the degree of the pointer:
See more about dp here.