题目大意:给出n,求1~n所有数的约数个数的和。

将“1~n所有数的约数”的模板中的factor[i*j].push_back(i)改为FactorCnt[i*j]++,最后再求一次和即可。

#include <cstdio>
#include <cstring>
using namespace std;

const int MAX_N = 1000010;

int Proceed(int n)
{
	static int FactorCnt[MAX_N];
	memset(FactorCnt, 0, sizeof(FactorCnt));
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n / i; j++)
			FactorCnt[i*j]++;
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans += FactorCnt[i];
	return ans;
}

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d\n", Proceed(n));
	return 0;
}

  

相关文章:

  • 2021-06-27
  • 2022-02-05
  • 2022-01-14
  • 2021-05-20
  • 2021-07-11
  • 2021-06-15
猜你喜欢
  • 2021-05-15
  • 2022-01-15
  • 2021-12-14
  • 2022-12-23
  • 2022-03-04
  • 2022-01-18
相关资源
相似解决方案