Question Name:LET’S BEGIN!

#include<iostream>
 
using namespace std;
 
#define MAX 1000005
 
int ans[MAX], count=0;
 
int solve(int X)
{
    //cout<<X<<endl;
    count++;
    if(ans[X]!=0){
        return ans[X];
    }
 
 
    int i, j, result=10*MAX, minResult = 10*MAX;
    if(X<2){
        return MAX*10;
    }
 
    result = solve(X-7) + 1;
    if(minResult > result){
        minResult = result;
    }
    result = solve(X-5) + 1;
    if(minResult > result){
        minResult = result;
    }
    result = solve(X-3) + 1;
    if(minResult > result){
        minResult = result;
    }
    result = solve(X-2) + 1;
    if(minResult > result){
        minResult = result;
    }
 
    ans[X] = minResult;
    //cout<<count<<" "<<X<<" = "<<ans[X]<<endl;
    return ans[X];
 
}
 
int main()
{
    int T;
    ans[2] = ans[3] = ans[5] = ans[7] = 1;
    cin>>T;
    while(T--)
    {
        int X, minstep=MAX*10;
        cin>>X;
        minstep = solve(X);
 
        if(minstep ==10*MAX )
            minstep=-1;
        cout<<minstep<<endl;
        //cout<<count<<endl;
 
    }
}
  • Problem Description
    February Easy Challenge 2015 is underway. Hackerearth welcomes you all and hope that all you awesome coders have a great time. So without wasting much of the time let’s begin the contest.

    Prime Numbers have always been one of the favourite topics for problem setters. 

    Aishwarya is a mathematics student at the Department of Mathematics and Computing, California. Her teacher recently gave her an intriguing assignment with only a single question. The question was to find out the minimum number of single digit prime numbers which when summed equals a given number X.

    Input:
    The first line contains T denoting the number of test cases. Each of the next T lines contains a single integer X.

    Output:
    Print the minimum number required. If it is not possible to obtain X using single digit prime numbers, output -1.

    Constraints:
    1<=T<=100
    1<=X<=10^6
  • Test Case 1
    Input (stdin)4
    7
    10
    14
    11
    Expected Output1
    2
    2
    3
  • Test Case 2
    Input (stdin)3
    5688
    11126
    17529
    Expected Output814
    1590
    2505

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro