APS - Amazing Prime Sequence
Bablu is very fond of Series and Sequences...
After studying Fibonacci Series in Class IX, he was impressed and he designed his own sequence as follows...
a = a = 0
For n > 1, a[n] = a[n - 1] + f(n), where f(n) is smallest prime factor of n.
He is also very fond of programming and thus made a small program to find a[n], but since he is in Class IX, he is not very good at programming. So, he asks you for help. Your task is to find a[n] for the above sequence....
Your code will be checked for multiple Test Cases.
First Line of Input contains T (<= 100), the number of Test Cases.
Next T lines contain a single number N. (1 < N < 10^7).
Single line containing a[n] i.e. nth number of the sequence for each test case.
Input: 3 2 3 4 Output: 2 5 7
@Karan Dev : Its because for high values your recursive function eats up all the stack memory.
my code works for n=10000, but not for , n=100000 or above. I checked 'smallest prime' function, it is working good for n=100000 or above. help.
should be moved to the tutorial section...
nice one :-D
i guess the test cases are randomly generated. The supposedly faster code working slowly...?
@abdelkarim ya man did it before the question was there on spoj
(Tjandra Satria Gunawan)(æ›¾æ¯…æ˜†):
@Ehor Nechiporenko: Your memory usage give me more idea to optimize my solution ;-) Thanks, haha...
The number 11,000,000 was in the input, but it seems to have been fixed now.