Solving 1731B Kill Demodogs with Modular Arithmetic

It took a lot of time and 2 rough pages to solve 😭 . 𝐃𝐚𝐲 𝟕𝟐/𝟏𝟎𝟎 – Competitive Programming (CodeForces) Solved: 1731B – Kill Demodogs A math-heavy problem since n is huge, so brute force / DP on grid is not possible. -- Path is fixed in structure → from (1,1) → (1,n) → (n,n) -- Each cell contributes i * j, so we need to derive a closed-form sum -- Final formula comes out to: 2022 × n(n+1)(4n−1) / 6 Then just compute it carefully using modular arithmetic. #Codeforces #CompetitiveProgramming #100DaysOfCode #Math #NumberTheory #ProblemSolving #DSA #Cpp #Algorithms

  • table

To view or add a comment, sign in

Explore content categories