(PPDIV) Perfect Power Divisors - Video Solution (APRIL20)

Hi,
I have created a video solution for the problem Perfect Power Divisors(PPDIV) under April long challenge 2020. The solution is presented in such a way that it shows the steps I took to arrive at the solution. I hope this video helps you understand the solution to the fullest.

If you understood the solution please do leave a like on the video.

Happy coding!

2 Likes
for(ll i=sqrn; i > 1; --i) {
    ll cnt = n / (i*i);
    ll j = n / (cnt+1);
    j = sqrt(j);
    if(j == i)
        --j;
    cout<<cnt<<" : "<<i<<" "<<j<<endl;
    ll sum = (i * (i+1LL))%MOD;
    sum = (sum * (2LL*i+1LL))%MOD;
    sum = (sum * inv6)%MOD;
    // assert(sum>=0);
    ll sum2 = (j * (j+1LL))%MOD;
    sum2 = (sum2 * (2LL*j+1LL))%MOD;
    sum2 = (sum2 * inv6)%MOD;
    // assert(sum2>=0);
    sum = (sum - sum2 + MOD)%MOD;
    // assert(sum>=0);
    ans += (sum * cnt)%MOD;
    ans %= MOD;
    // assert(j > 0);
    i = j+1;
}

In you code, you wrote a logic
if(j == i)
–j;
what’s the need of it? and in which case i and j could be equal?

1 Like

While debugging i found that i is equal to j for few i values. In that case I want to still add i. So im doing j–.

1 Like