Facing TLE in a problem

Revision en2, by Surgeon_of_Hell, 2024-10-30 15:45:41

Problem Statement: Given an integer $$$ n $$$, find the sum of $$$ f(k) $$$, where $$$ f(k) = 1 + 2 + 3 + \ldots + k $$$ and $$$ 1 <= k <= n $$$ . Output the result modulo $$$ 10^9 + 7 $$$. max(n) = $$$10^9$$$.

MY approach: Firstly , very very sorry for my poor english. My approach was to use the formula n(n + 1)/2 in a loop. But I am getting TLE every time. But I don't know how to fix it any further. I first I used 2 nested loops and then only one loop. But not working.

Can some generous person help me?

Tags problem

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English Surgeon_of_Hell 2024-10-30 15:46:11 436 Reverted to en2
en3 English Surgeon_of_Hell 2024-10-30 15:45:51 436 Reverted to en1
en2 English Surgeon_of_Hell 2024-10-30 15:45:41 436 (published)
en1 English Surgeon_of_Hell 2024-10-30 15:31:07 228 Initial revision (saved to drafts)