题目地址:点击打开链接
这道题是因子求和,传统的方法会超时
#include<iostream>
using namespace std;
const int MAX = 500000+5;
int A[MAX];
int main()
{
int t;
int n;
cin>>t;
for( i = 1 ;i < MAX/2; i++)
{
for( int j = i*2; j <MAX; j += i) //求因子之和,时间复杂度o(logn)
A[j] += i;
}
while(t--)
{
cin>>n;
cout<<A[n]<<endl;
}
return 0;
}