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
When will you mark the multiple of the primes...on that time you can store the prime of the multiples in the multiples... Hope it helps to avoid TLE... :)
Easy problem if you use the concept of sieve of Eratosthenes
nice for beginner like me :)
Please help....my code is running fine in code blocks but in Spoj it is giving Compilation error and sometimes runtime error
easy problem,done using sieve,,,,
@dushyant ...no need of unsigned if using sieve
not reading @dushyant comment costed me 1 WALast edit: 2015-08-11 14:09:50
Those who are getting WA change everything to unsigned long long, same for those who are getting TLE. :-)
rojers's algorithms rocks......ac in 1/2 go...... only one line code :P :)