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 Beta Round #53 (A. Square Earth?)

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 represented in base b using   namespace  std; typedef   long   long ...

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...

AtCoder Beginner Contest 237(D - LR insertion)

Problem solving criteria:stack (https://www.cplusplus.com/reference/stack/stack/) Think about the first input: LRRLR That means  0 ->(L)-> 1 ->(R)-> 2 ->(R)-> 3 ->(L)-> 4 ->(R)-> 5 so we just need to save first R right number  in  an  array (vector) & other number saves  in  a stack. 0 ->(L)-> 1   general  array (vector)       stack( 0 )   top of stack= 0 1 ->(R)-> 2   general  array (vector)= 1      stack( 0 )   top of stack= 0 2 ->(R)-> 3   general  array (vector)= 1 , 2    stack( 0 )   top of stack= 0 3 ->(L)-> 4   general  array (vector)= 1 , 2    stack( 0 , 4 )...