You are viewing a single comment's thread. Return to all comments →
Can someone just tell me why am I getting timeout error in some problems, wrong in some and right in some
long int num[1000],ans[2]; long int Base,num_dig,totalsum=0;
int summation(int a) {int sum=0; for(int i=0;i<=a;i++) sum+=num[i]; return sum;}
void convert (int i) {int a=-1; ans[1]=i; double sum1=0,sum2=0,num1=i; while(i>0) {a++; num[a]=i%Base; i/=Base; } sum1=summation(a); sum2=summation(a/2);
if(a%2==0) sum1+=num[a/2]; if((sum1)==sum2*2) {ans[0]=1;ans[1]=num1;} else {ans[0]=0;ans[1]=0;}
}
int main() { long int count=0; cin>>Base; cin>>num_dig;
int sum=0,num; for(int i=0;i<num_dig;i++) {cin>>num; sum+=num*pow(Base,num_dig-i-1); } for(int i=1;i<=sum;i++) {convert(i); count=count%1004535809; totalsum=totalsum%1004535809; count+=ans[0]; totalsum+=ans[1];} cout<<count<<" "; cout<<totalsum; return 0;
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #217: Balanced Numbers
You are viewing a single comment's thread. Return to all comments →
Can someone just tell me why am I getting timeout error in some problems, wrong in some and right in some
long int num[1000],ans[2]; long int Base,num_dig,totalsum=0;
int summation(int a) {int sum=0; for(int i=0;i<=a;i++) sum+=num[i]; return sum;}
void convert (int i) {int a=-1; ans[1]=i; double sum1=0,sum2=0,num1=i; while(i>0) {a++; num[a]=i%Base; i/=Base; } sum1=summation(a); sum2=summation(a/2);
}
int main() { long int count=0; cin>>Base; cin>>num_dig;
}