http://acm.hdu.edu.cn/showproblem.php?pid=1215
类似于筛选法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h>
2 #include <string.h>
3 const int N=500001;
4 int f[N];
5 int main()
6 {
7 memset(f,0,sizeof(f));
8 for (int i=1;i<N;i++)
9 for (int j=i+i;j<N;j+=i) f[j]+=i;
10 int T,n;
11 scanf("%d",&T);
12 while (T--)
13 {
14 scanf("%d",&n);
15 printf("%d\n",f[n]);
16 }
17 return 0;
18 }