We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If you're using a language without bigints or the like, be careful to do modular arithmetic early. I took a day figuring out why I was passing every test but 2 because of that.
#include<bits/stdc++.h>usingnamespacestd;#define REPP(I, A, B) for(int I = (A); I < (B); ++I)#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)#define MS0(X) memset((X), 0, sizeof((X)))typedeflonglongLL;constintMOD=1e9+7;constintSIZE=600000;LLdp3[SIZE],mul[SIZE],record[SIZE];voidpre(){REPP(i,1,SIZE){dp3[i]+=(LL)(i+i+1)*(i+i+1)*(i+i+1)-(LL)(i+i-1)*(i+i-1)*(i+i-1);for(intj=i+i;j<SIZE;j+=i){dp3[j]-=dp3[i];}dp3[i]+=dp3[i-1];dp3[i]%=MOD;}}intmain(){pre();CASET{MS0(record);MS0(mul);LLN,an=0;intM,D;scanf("%lld%d%d",&N,&M,&D);LLnow=1;while(now<=N){LLv=N/now;LLnxt=N/v;if(v>=M){if(v%D==0){if(nxt<SIZE)an+=dp3[nxt];elsemul[v]++;if(now-1<SIZE)an-=dp3[now-1];elsemul[v+1]--;}}now=nxt+1;}intker=1;while(N/ker>=SIZE)ker++;intbb=ker;for(ker--;ker>0;ker--){LLn=N/ker;LLme=(n+n+1)%MOD;record[ker]=(me*me%MOD*me%MOD-1);for(now=2;ker*now<bb;now++)record[ker]-=record[ker*now];while(now<=n){LLv=n/now;LLnxt=n/v;if(v<SIZE){record[ker]-=dp3[v]*(nxt-now+1);record[ker]%=MOD;}now=nxt+1;}record[ker]%=MOD;if(record[ker]<0)record[ker]+=MOD;if(mul[ker])an+=mul[ker]*record[ker];}an%=MOD;if(an<0)an+=MOD;cout<<an<<endl;}return0;}
T T
Could anyone please help to shed some light on this one? I have no idea on how to handle this gracefully..
Any help will be greatly appreciated! :)
No more comments
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
If you're using a language without bigints or the like, be careful to do modular arithmetic early. I took a day figuring out why I was passing every test but 2 because of that.
C++ solution
T T Could anyone please help to shed some light on this one? I have no idea on how to handle this gracefully.. Any help will be greatly appreciated! :)