FNDTERM Editorial

Problem link
Author: @maazbinasad3
Tester: @prasoonjain006
Editorialist: @maazbinasad3
Difficulty: Cakewalk
Prerequisites : Sequences and Series

Problem
Find the Nth term of given sequence 1,3,6… so on.

Observation 1
This sequence is the triangular numbers.

Observation 2
The Nth term represents sum of first n natural numbers given by (n*(n+1))/2.

Solution

Setter’s solution

#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<stack>
#pragma GCC optimize("O2")
    typedef long long int ll;

using namespace std;
int main(){
    ll test;
    cin>>test;
    while(test--){
        ll n;
        cin>>n;
        cout<<(n*(n+1))/2<<"\n";
        }
}
1 Like