Sort by

recency

|

3 Discussions

|

  • + 1 comment

    i need help. my code is running correctly. but when i try to print the sum of k-number, it gives wrong answer..

    int main()
    {
    int l,r,k,i,sum=0;
    
    scanf("%d%d%d",&l,&r,&k);
    for(i=l;i<=r;i++)
    {   
    
        int x=i,cnt=0,a=k,b,c=i,d=0,e,f=i,g,w;
    
        while(x!=0)
        {
            cnt++;
            x=x/10;
    
        }
    
        if(cnt<=k)
        {
            sum=sum+i;
    
        }
    
    
        else
        {
            while(a!=0)
            {
                b=c%10;
                d=d+b;
                a--;
                c=c/10;
            }
    
            while(cnt!=0)
            {
                if(cnt<=k)
                {
                    e=f%10;
                    g=g+e;  
                }
                f=f/10;
                cnt--;
            }
    
    
    
            if(d==g)
            {
                sum=sum+i;
            }
        }
    }
    
    printf("%d",sum);   /*when i include this line in my code,                          it will give wrong answer.*/
    return 0;
    }
    
  • + 1 comment

    not able to minimize the running time. plz help....

    include

    include

    include

    include

    include

    using namespace std;

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    long long int L,R,i,sum=0; int sum1,sum2,n,x,k,j,t; int a[18];
    cin>>L>>R>>k; for(i=L;i<=R;i++) { j=i; n=0; while(j!=0) { a[n]=j%10; j=j/10; n++; } if(n<=k) { sum=(sum+i)%1000000007;
    continue; } sum1=0,sum2=0; for(t=0;t

        if(sum1==sum2)
      sum=(sum+i)%1000000007;    
    }
    cout<<sum;
    return 0;
    

    }

  • + 2 comments

    In challenges some problems marked like a unsolved, but actually it is solved, and exists accepted in submissions tab. For example, this problem :).

No more comments