Getting tle during submission

I am solving this question from codeforces…
https://codeforces.com/contest/1091/problem/C
This is my solution…
https://codeforces.com/contest/1091/submission/97815996
It is showing tle…
I have looked into editorial… But the formula with which it is calculating fun value of every ‘k’, doesn’t striking me…
Please share some idea… How it is calculating fun vlaue with that formula… or any other approch…
Thanks…

Hey @ashishnnnnn

Here see this

int main() {

  ll i, j, k;
  ll n, m;
  ll x, y, a, d;

  set<ll> ans;
  set<ll> divs;

  x = sqrtl(n * 1.0) + 10;
  for (i = 1; i <= x; i++) {
    if (n % i == 0)
      divs.insert(i), divs.insert(n / i);. //Pushing all divisors into set
  }

  a = 1;
  for (ll e : divs) {//itterating ober divisors
    m = n / e; //for eth divisor no of terms =n/e
    x = a + (m - 1) * e; //Caluclating last term of AP
    y = m * (x + a); //2\*Sum of AP: no of terms*(first+last)
    y /= 2; 

    ans.insert(y);
  }

  for (ll e : ans)
    cout << e << endl;

  return 0;
}

Thank you very much… :slight_smile:
Got the whole logic… :slight_smile:

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.