Skip to main content

Technocup 2018 - Elimination Round 2 (C. Maximum splitting)

 

Bismillahir Rahmanir Rahim

4 is the lowest composite number so we must think about 4 divisibility(0-3)

Case 1:if number divided by 4 the it is OK
Case 2:After dividing 4 the number it's reminder is 1 then
       num=1 output is (-1).
       num=5 output is (-1).
       after that number is 9 other is 4.alike 13=9+4 21=9+4+4+4
Case 3:After dividing 4 the number it's reminder is 2 then
       num=2 output is (-1).
       after that number is 6 other is 4.alike 10=6+4 26=6+4+4+4+4+4
Case 4:After dividing 4 the number it's reminder is 3 then
       num=3 output is (-1).
       num=7 output is (-1).
       num=11 output is (-1).
       after that number is 9 & 6, other is 4.alike 15=9+6 19=4+6+9 31=4+4+4+4+6+9

///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
  angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll tst,num;
    cin>>tst;
    while(tst--)
    {
        cin>>num;
        if(num%4==0) cout<<num/4<<endl;
        else if(num%4==1)
        {
            if(num==1 || num==5) cout<<"-1"<<endl;
            else cout<<((num-9)/4)+1<<endl;
        }
        else if(num%4==2)
        {
            if(num==2) cout<<"-1"<<endl;
            else cout<<((num-6)/4)+1<<endl;
        }
        else
        {
            if(num==3 || num==7 || num==11) cout<<"-1"<<endl;
            else cout<<((num-15)/4)+2<<endl;
        }
    }
    return 0;
}
///Alhamdulillah

Problem Link: https://codeforces.com/problemset/problem/870/C

Comments

Popular posts from this blog

Codeforces round 1676(A. Lucky?)

Just count the  first three  &  last three  number ///Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is repres...

Codeforces round 1661(B. Getting Zero)

using   second operation  the answer is maximum is  15  because  2 15 =32768 so we need to  pre-calculate all the illegible input 0 to 32768   using  second operation Then  just increment 1(using first operation)  from input check is it  minimum is not ! ///Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int...

Codeforces round 1676(E. Eating Queries)

Just use the lower bound & check is it greater than the sum or not Lower bound:https://www.geeksforgeeks.org/upper_bound-and-lower_bound- for -vector- in -cpp-stl/ ///Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180...