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.