競プロ典型 015

https://atcoder.jp/contests/typical90/tasks/typical90_o

これは、アルゴリズムと数学 101と同じ問題です。