I'm doing a C ++ program to solve the 2597 math exercise of the ONLINE JUDGE platform below the problem description below.
IstarteddoingtheprograminC++,butrealizethattheinputistoolarge,ItriedtomakeaDPtopreprocesseverythingbefore,butIcannotcreateavectorofsize10^9!!Followtheprogramforyouguystotakealook**
#include<bits/stdc++.h>usingnamespacestd;typedeflonglongintbigint;bigintcontaDiv(bigintdividendo){bigintdiv=0;bigintk=1;bigintm=1;bigintdivisor=1;while(divisor<=sqrt(dividendo)){if(dividendo%divisor==0){//cout<<"(div/div)"<<(dividendo/divisor)<<endl;
if((dividendo/divisor)==divisor)
{
div+=1;// cout<<"one"<<endl;
}
else
{
div+=2; //cout<<"two"<<endl;
}
}
++divisor;
}
return div;
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
bigint c,n,vl;
cin>>c;
while(c--) {
cin>>n;
int ans = 0;
for(int i=1;i<=n;++i) {
// cout<<"DIV de "<<i<<" = "<<contaDiv(i)<<endl;
if(contaDiv(i)%2==0) {
++ans;
}
}
cout<<ans<<endl;
}
return 0;
}
** If someone can help me ... how to solve this problem !! At the moment this code is receiving Time Limit Exceed !! **