Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1215
Scream .. It is really not suitable for the number topic .. Various timeouts, re...
Well, the question is very clear, and how to do it is the same thing.
The limit of 500000 cannot be violent.
In this case, the tables are the most earthy.
How to build a table?
First, a factor must include a multiple of a number.
Remember this ..
ACCode:
# Include <iostream> using namespace STD; int A [500001]; void fun () {int I, j; for (I = 1; I <= 500000; I ++) // 1 each person adds a [I] = 1; for (I = 2; I <= 250001; I ++) // just half of it, it is meaningless {for (j = I + I; j <= 500000; j + = I) // as long as the number is a multiple of I, it must contain the I factor, I will not add it myself. From the next part of I, {A [J] + = I; // so I will be added.} int main () {int M, N; fun (); scanf ("% d", & M); While (M --) {scanf ("% d", & N ); printf ("% d \ n", a [n]);} return 0 ;}