1475B - New Year's Number - CodeForces Solution


brute force dp math *900

Please click on ads to support us..

Python Code:

t=int(input())

for i in range(t):
    n=int(input())
    
    m=n%2020
    d=n//2020

    if(m<=d):
        print("YES")
    
    else:
        print("NO")

C++ Code:

#include <bits/stdc++.h>
#define ll             long long
#define pb             push_back
#define ld             long double
#define lala           for(ll i=0;i<n;i++)
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
using namespace std;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
void vin( vector<int> &v , int n ){for (int i = 0; i < n; i++){int x ;cin >> x; v.push_back(x);}}
void vout(vector<int> &v){for (int i = 0; i < v.size(); i++){cout << v[i] << " " ;}cout << endl;}
long long lcm(int a, int b){    return (a / gcd(a, b)) * b;}
int digits_count(int n){int d=0;while(n != 0){d++;n /=10;}return d;}

vi dp(1e6+1,-1);
bool rec(int n)
{
    if(n<2020) return 0;
    if(n==2021 || n==2020) return 1;
    if(dp[n]!=-1) return dp[n];
    return dp[n]=(rec(n-2020) || rec(n-2021));
}

void hello()
{
    ll n;
    cin>>n;
    // cout<<rec(n)<<endl;
    if(rec(n)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
int main()
{
    int t=1;
    cin>>t;
    while(t--)
    {
        hello();
    }
}


Comments

Submit
0 Comments
More Questions

510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction
388A - Fox and Box Accumulation
451A - Game With Sticks
768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops