include <bits/stdc++.h>
using namespace std;
define MAX 5000001
define modulo 1000000007
long long F[MAX]; bool v[MAX]; long len, sp[MAX];
void Sieve(){ for (long i = 2; i < MAX; i += 2) sp[i] = 2;//even numbers have smallest prime factor 2 for ( long i = 3; i < MAX; i += 2){ if (!v[i]){ sp[i] = i; for (long long j = i; (j*i) < MAX; j += 2){ if (!v[j*i]) v[j*i] = true, sp[j*i] = i; } } } }
int main() { Sieve(); //This function is for pre-processing. This will store smallest prime factor of n in sp[n] long long t,r,l; cin >> t>> l >>r; F[0]=0;F[1]=0;F[2]=1; //Base Cases for (long i = 3; i < MAX; ++i){ F[i] = ((i*(sp[i]-1)/2)%modulo + F[(i/sp[i])]%modulo)%modulo; } long long ans=0, mod=1; for (long i = l; i <= r; ++i) { ans += (mod*F[i])%modulo; ans = ans % modulo; mod=(mod*t)%modulo; } cout<<ans<<endl; return 0; }
This is not the code's error report, but only advice. I looked at this code:
I think you should make more readable code.
Readable codes can read, or find bug faster, for you and for everyone.
How about a link to your submission instead of copypasta, because no one can read this.
Sorry I didn't thought copy and paste will cause a trouble
Here is the link to my solution : https://github.com/Akshay9414/Practice/blob/master/822D.cpp
Plz help
This code works fine on my machine.
What testcase does it fail? Are you getting TLE or WA?
WA in test case 2
I get correct answers for all of the test cases on my machine.
I don't see why the server would produce a WA.
I again checked the results by submitting the code on the link and still getting WA in test 2. I even took an accepted solution and compared the answers produced by it and my code in around 10^5 randomly generated test cases and results were fine. If I can't identify the case in which my code fails then I would not be possible to debug. Do you have any idea why this is happening that it is running fine on your machine and not on mine?