Project Euler #217: Balanced Numbers

Sort by

recency

|

11 Discussions

|

  • + 0 comments

    Something is wrong with the server. image

  • + 0 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;
    

    }

  • + 0 comments

    @khalid_t would you consider disclosing base and number of digits of test cases 3 until 6 ? I see a lot of people stuck at scores 0.1 (only first 3 test cases) and 0.29 (only first 4). Also I suspect that timeouts in test cases above 7 are somehow associated with failing the first ones...

  • + 0 comments

    and how we are getting the sequence

    1,2,3,4,5,6,7,8,9,10,12,24,36............

    how ? please explain

  • + 0 comments

    can you please explain me how that would be 240 for second case.

    i did nt understand what exactly balanced means. please any one explain me ?