hdu1215(七夕节,因子之和)

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

#define CLR(arr, what) memset(arr, what, sizeof(arr))
const int N = 500002;
const int M = 250000;
int a[N] = {0, 0};

void fash()
{
	for(int i = 2; i < N; ++i) //因子初始化为1
		a[i] = 1;
	for(int i = 2; i <= M; ++i) //一半即可
		for(int j = 2 * i; j < N; j += i)
			a[j] += i;
}

int main()
{
	fash();
	int ncase;
	scanf("%d", &ncase);
	while(ncase--)
	{
		int num;
		scanf("%d", &num);
		printf("%d\n", a[num]);
	}
	return 0;
}

你可能感兴趣的:(hdu1215(七夕节,因子之和))