AFS - Amazing Factor Sequence
Bhelu is the classmate of Bablu who made the Amazing Prime Sequence.
He felt jealous of his classmate and decides to make his own sequence. Since he was not very imaginative, he came up with almost the same definition just making a difference in f(n):
- a[0] = a[1] = 0.
- For n > 1, a[n] = a[n - 1] + f(n), where f(n) is the sum of positive integers in the following set S.
- S = {x | x < n and n % x = 0}.
Now, Bablu asked him to make a code to find f(n) as he already had the code of his sequence. So, Bhelu asks for your help since he doesn't know programming. Your task is very simple, just find a[n] for a given value of n (< 10^6).
Input
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 positive integer N. (1 < N < 10^6).
Output
Single line containing a[n] i.e. n-th number of the sequence for each test case.
Example
Input: 3 3 4 5 Output: 2 5 6
Explanation
f(2) = 1 {1} f(3) = 1 {1} f(4) = 3 {1, 2} f(5) = 1 {1}
hide comments
(Tjandra Satria Gunawan)(曾毅昆):
2013-03-16 19:25:52
solved using 12 different(?) programming language, haha :-D First time I do that on SPOJ... ;-) |
|
(Tjandra Satria Gunawan)(曾毅昆):
2013-03-16 16:14:14
aaa! I'm late... I never imagine that O(sqrt(n)) exists... I should think out of the box to notice that...
|
|
Francky:
2013-03-16 11:39:04
Oh Oh, it seems Robert Gerbicz shows us that a Python solution will be possible. Good news, and great challenge.
|
|
(Tjandra Satria Gunawan)(曾毅昆):
2013-03-16 05:37:29
I wonder if 3s time limit is too long/relax (for C/C++ user)? AC in 0.25s without fast I/O..
|
|
Shaily Mittal:
2013-03-15 20:23:45
@Francky: What is the complexity of the code?
|
|
Francky:
2013-03-15 16:29:11
My all first (very poor) C-code (15-01-2012) for DIVSUM, with minor modifications, can get AC. And I bet it will very hard or quite impossible to get AC in Python. :-(
|
Added by: | c[R]@zY f[R]0G |
Date: | 2013-03-15 |
Time limit: | 1s |
Source limit: | 5000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |