1140D - Minimum Triangulation - CodeForces Solution


dp greedy math *1200

Please click on ads to support us..

Python Code:

n = int(input())
ans = 0
for i in range(n-2):
    ans+=(i+2)*(i+3)
print(ans)

C++ Code:

 #include <iostream>
#include <string>
#include<stack>
#include<unordered_set>
#include<queue>
#include<deque>
#include<algorithm>
#include <cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<iomanip> // setprecision(number)   cout << fixed << setprecision(6);
#include<ctype.h> //  towlower toupper
#define sa(a,n) sort(a,a+n)
#define endl   "\n"
#define ll long long
#define tt int
#define str string
#define fs(n)              fixed<<setprecision(n)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define leadzero(a) __builtin_clz(a)        // count leading zeroes
#define trailzero(a) __builtin_ctz(a)       // count trailing zeroes
#define bitcount(a) __builtin_popcount(a)   // count set bits
using namespace std;
ll prime[10000005];
void  sieve() {
    for (ll x = 2; x < 1e7; x++)
    {
        if(x!=2&&x%2!=0)
            prime[x] = 1;
    }
    for (ll x = 3; x * x < 1e7; x += 2) 
    {
        if (prime[x]) 
        {
            for (int j = x * x; j < 1e7; j += x + x)
                prime[j] = 0;
        }
    }
}
bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
 
    return true;
}
ll lcm(ll x,ll y)
{
    return x * y / __gcd(x, y);
}
bool cm  (pair< int,string>p1  ,pair< int,string>p2)
 {
     if(p1.first==p2.first)
     return p1.second<p2.second;

      return p1.first>p2.first;
     
 }
 
 
// auto  it  = maxx.end(); it--; k=*it erase(it) ,, set<ll,greater<>>s;
//getline(cin, s1)
//auto it=upper_bound(v.begin(),v.end(),m);
int main() {
    fast;
    ll n,sum=0;
    cin>>n;
    for(ll x=2;x<n;x++)
        sum+=(x*(x+1));
        
       cout << sum;
}
  


Comments

Submit
0 Comments
More Questions

169B - Replacing Digits
171D - Broken checker
380C - Sereja and Brackets
1281B - Azamon Web Services
1702A - Round Down the Price
1681C - Double Sort
12A - Super Agent
1709A - Three Doors
1680C - Binary String
1684B - Z mod X = C
1003A - Polycarp's Pockets
1691B - Shoe Shuffling
1706A - Another String Minimization Problem
1695B - Circle Game
1702B - Polycarp Writes a String from Memory
1701A - Grass Field
489C - Given Length and Sum of Digits
886B - Vlad and Cafes
915A - Garden
356A - Knight Tournament
1330A - Dreamoon and Ranking Collection
1692B - All Distinct
1156C - Match Points
1675A - Food for Animals
1328C - Ternary XOR
1689A - Lex String
1708B - Difference of GCDs
863A - Quasi-palindrome
1478A - Nezzar and Colorful Balls
1581B - Diameter of Graph