# Sum of odd series

Practice

Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD

# DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

Math .

# PROBLEM:

You have given N and Sum of first N odd number is given but in that one number is missing you have to find that number

for example : N = 4 Sum = 13

In above example N=4 is given and sum=13 is given we have to find missing number in series .

Sum of first 4 odd number is 1+3+5+7 = 16

But sum is given 13 that is the missing number is 3

# EXPLANATION:

You simply given N and sum of first N odd number in that one term is missing so if we subtract the sum given in question with original sum that given we will get our answer.
for example N=5 sum=20
Sum of first N odd number is 25 but sum is given 20 so if we subtract 20 with 25 we will get our answer
formula for sum of first N odd number is N*N

# SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
long long int n,sum;
cin>>n>>sum;
long long int k=n*n;
long long int pp=k-sum;
cout<<pp;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
long long int n,sum;
cin>>n>>sum;
long long int k=n*n;
long long int pp=k-sum;
cout<<pp;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
long long int n,sum;
cin>>n>>sum;
long long int k=n*n;
long long int pp=k-sum;
cout<<pp;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}