由于数据过大,使用基本的判断余数法会超时,需要先打表。
#include <iostream>
using namespace std;
const int MAXN = 500005;
int arr[MAXN];int main()
{for (int i = 1; i < MAXN / 2; i++){for (int j = i * 2; j < MAXN; j += i)arr[j] += i;}int T;int n;cin >> T;while (T--){cin >> n;cout << arr[n] << endl;}return 0;
}
继续加油。