192A - Funky Numbers - CodeForces Solution


binary search brute force implementation *1300

Please click on ads to support us..

C++ Code:

#include<cstring>
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <cstring>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ull N = (1e7)/2+10;
const ll INF =1e18;
const ull M= 998244353;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
//    cin >> t;
    while(t--){
         ll n;
         cin >> n;
         set<ll>s;
         vector<ll>v;
         for(int i = 1 ; i < 1e5 ; i++){
            ll bng  = (1LL*i*(i+1)/2);
            s.insert(bng);
            v.push_back(bng);
         }
         ll f = 0 ;
         for(int i = 0 ; i < v.size()  ;i++){
            if(s.find(n-v[i]) != s.end() && n-v[i] > 0){
                f=1;
                break;
            }
         }
         if(f) cout << "YES" <<endl;
         else cout << "NO" <<endl;


    }














    return 0;
}


Comments

Submit
0 Comments
More Questions

1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory
1196A - Three Piles of Candies
299A - Ksusha and Array
448B - Suffix Structures
1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site
1316A - Grade Allocation
838A - Binary Blocks
1515D - Phoenix and Socks
1624D - Palindromes Coloring
1552F - Telepanting
1692G - 2Sort
1191A - Tokitsukaze and Enhancement
903A - Hungry Student Problem
52B - Right Triangles
1712A - Wonderful Permutation
1712D - Empty Graph
1712B - Woeful Permutation
1712C - Sort Zero
1028B - Unnatural Conditions