Boltu vs Balti

Boltu and Balti are two friends. Boltu is a great programmer whereas Balti is a newbie programmer. B…

Click here to read the complete problem statement.

If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

printf(“Sum of %d to %d is:%d\n”, m, n, sum);…printing the output in this format i am getting wrong answer. But my output is right for all kind of cases i tested. what can i do for this problem …Need help.

Using long long int data type ur code will be ac

I don’t understand. Sum = what? And will m an n be in scanf function?

I used unsigned long long for all data but judged as wrong what should I do

Check you printed “Sum” as “sum”. @KAS.shim1998

I have a confusion. You says

N and M. Which will look like : “Sum of X to Y is: Z;“
But output is much different.

which one is correct(JAVA)?
String str = “Sum of “+N+” to “+M+” is: “+sum+”;”;
String str = “Sum of “+N+” to “+M+” is-> “+sum+”;”;
I tried both but it keep showing wrong…
Or what will be the correct format by the way??

there are no problem but still rejected.why??

#include <stdio.h>
int main(){
long long int N,M,X,Y;
while(scanf(“%lld %lld”,&N,&M)==2){
if(0<=N && N<M && M<=1000000000){
printf(“Sum of %lld to %lld is → %lld;\n”, N+1, M, X-Y);
return 0;

The value of N may be smaller than M, so you must exchange two values when N is smaller than M.
Here is my solution using Python3.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    while True:
            n, m = map(int, input().strip().split())
            n, m = min(n, m), max(n, m)
            s = (n + m) * (m - n + 1) // 2
            print('Sum of {0} to {1} is -> {2};'.format(n, m, s))
        except EOFError:
def input_num(a,b):
total = 0
for i in range(a,b+1):
    total += i
    sum_num = total
return f'Sum of {a} to {b} is -> {sum_num};'


what is the problem here?

a maybe smaller than b, you should think about input_num(7, 3) to print “Sum of 7 to 3 is -> 25;”

What is the problem here!!. ( C ). Someone please help me!!

int main()
long long n=0,m=0;
long long swap = n;
long long diff = abs(n-m)+1;
long long sum = (diff*(2*n+(diff-1)))/2;

printf("Sum of %lld to %lld is -> %lld;",n,m,sum);
return 0;


a maybe smaller than b, you should think about input_num(7, 3) to print “Sum of 7 to 3 is -> 25;”
so ‘range(a, b+1)’ should be ‘range(min(a,b), max(a,b) + 1)’

1 Like

#include <bits/stdc++.h>

using namespace std;

int main() {
unsigned long long int n,m;
if(n>m) {
int t=m;
cout<<"Sum of “<<n<<” to “<<m<<” is → "<<(m+n)*(m-n+1)/2<<‘;’;
I have the same algo. But where is the problem? Showing wrong answer.

This is too easy problem indeed
use this theorem
printf(“Sum of %lld to %lld is → %lld;\n”,small+1,big,big*(big+1)/2-(small*(small+1))/2);

using namespace std;

int main() {
long long n , m;
long long sum=0;
for(int i=n;i<=m;i++){
for(int i=m;i<=n;i++){
cout<<“Sum of “<<n<<” to “<<m<<” is → “<<sum<<”;”;
return 0;
this code show the out put at the same what the problem want but it is not accepted

Of course, it will not. It is a End Of File (EOF) input type problem.
This means you have to take the values of n and m unless the program reaches the end of the input file and you have to calculate and output the result at the same time.

Notice that the numbers of test cases is not specified in this problem and output is calculated for every input until the end. In the sample, there are two lines dedicating two values of n and m and so we will calculate and output the result 2 times for each inputs.

See this input - How to read until EOF from cin in C++ - Stack Overflow.

I have a difficulty in solving this problem. How do I take numbers as input until encountering EOF in C? Do I read it as a char type, float type or int type? I’ve gone through several articles in stack change but still understand nothing. Please help.


using namespace std ;

int main() {
long long int n , m , sum1 , sum2 ,sum ;
cin>> n >> m ;

if(m<n) { sum1 = (n*(n+1))/2 ;
        sum2 = ((m-1)*(m-1+1))/2 ;

        sum = sum1-sum2;

cout << "Sum of " << m << " to " << n << " is: " << sum <<";"  << endl ; }
else {
        sum1 = ((n-1)*(n-1+1))/2 ;
        sum2 = (m*(m+1))/2 ;
        sum= sum2 - sum1 ;
    cout << "Sum of " << n << " to " << m << " is: " << sum <<";"  << endl ;

return 0 ;


please help… why is it not getting accepted ?

#Please tell me what the problem is with the output. I’m getting WA
print(“Sum of {} to {} is → {};”.format(N,M,sum(H)))