Boltu and Balti are two friends. Boltu is a great programmer whereas Balti is a newbie programmer. But Balti thinks that he is also a great programmer, but Boltu can’t accept Balti as a great programmer. Now Boltu challenges Balti to solve a task to prove himself as a great programmer. Balti accepts that challenge.

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.

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+”;”;
Or
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??

#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){
X=(M*(M+1))/2;
N=N-1;
Y=(N*(N+1))/2;
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:
try:
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:
break

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

#include<stdio.h>
#include<stdlib.h>
int main()
{
long long n=0,m=0;
scanf("%lld%lld",&n,&m);
if(m<n)
{
long long swap = n;
n=m;
m=swap;
}
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)’

int main() {
unsigned long long int n,m;
cin>>n>>m;
if(n>m) {
int t=m;
m=n;
n=t;
}
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
small=small-1;
printf(“Sum of %lld to %lld is -> %lld;\n”,small+1,big,big*(big+1)/2-(small*(small+1))/2);

int main() {
long long n , m;
long long sum=0;
cin>>n>>m;
if(n<m){
for(int i=n;i<=m;i++){
sum=sum+i;
}
}
else{
for(int i=m;i<=n;i++){
sum=sum+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.

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.

#Please tell me what the problem is with the output. I’m getting WA
N,M=map(int,input().split())
H=list(range(N,M+1))
print(“Sum of {} to {} is -> {};”.format(N,M,sum(H)))