Prime Numbers Again
Practice
4.4 (38 votes)
Ad Hoc
Approved
Dynamic programming
Easy
Open
Problem
46% Success 11216 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Panda can do any problem anytime and anywhere. Panda is doing an extensive research on prime numbers. Milinda has got a question for Panda. The only way for Panda to impress Milinda is by solving this question.
Given a number N, find the minimum number of primatic numbers which sum upto N.
A primatic number refers to a number which is either a prime number or can be expressed as power of prime number to itself i.e. primeprime e.g. 4, 27, etc.
Note: 8, 32, etc are not primatic numbers.
Panda is very sad since he is unable to solve the problem. Please help Panda in solving this problem.

enter image description here

Input Format:
The first line will contain two integers: T, the number of test cases.
Each test case consists of a single integer N.

Output Format:
For each query output the minimum number of primatic numbers which can sum upto N.

Constraints:
1 <= T <= 105
2 <= N <= 104

Subtask 1:
T = 100, 2 <= N <= 1000 - 20 points

Subtask 2:
T = 105, 2 <= N <= 104 - 80 points

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
Depth First SearchEasyGraphsImplementationRecursion
Points:20
1040 votes
Tags:
Ad-HocEasyImplementation
Points:20
38 votes
Tags:
Dynamic ProgrammingEasy