HDU 5528 Count a * b(数论)

k(n)=n*n-f(n)

可以知道对于一个k(p1^a1*p2^a2....pn^a2)=k(k1^a1)*....*k(kn^an)

然后又对于k(p^a)=(a+1)*(p^a)-k*(p^a-1)

那么对于g(n)=约数平方和+素数的h的和的乘机


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;
#define sp system("pause")

typedef long long ll;
typedef unsigned long long  ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;

const int MAXN = 32000 + 500;
int prime[MAXN + 1];
vector<int>myp;

void getprime()
{
	memset(prime, 0, sizeof prime);
	for (int i = 2; i <= MAXN; i++)
	{
		if (!prime[i])prime[++prime[0]] = i, myp.push_back(i);
		for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++)
		{
			prime[prime[j] * i] = 1;
			if (i%prime[j] == 0)break;
		}
	}
}

vector<pii>fac;
void getfac(int x)
{
	for (int i = 0; i < myp.size(); i++)
	{
		int cot = 0;
		while (x%myp[i] == 0)x /= myp[i], cot++;
		if (cot)fac.push_back(pii(myp[i], cot));
	}
	if (x>1)fac.push_back(pii(x, 1));
}

int main()
{
	int T;
	getprime();
	cin >> T;
	while (T--)
	{
		int x;
		scanf("%d", &x);
		ull tx = x;
		fac.clear();
		getfac(x);
		ull all = 0;
		//for (ull i = 1; i*i <= tx; i++)
		//	if(tx%i==0)all += i*i,all+=(tx/i)*(tx/i);
		ull now = 1;
		for (int i = 0; i < fac.size(); i++)
		{
			ull diall = 1; ull nowplus = fac[i].first;
			ull nowpow = 0; ull cotall = 0;
			for (int j = 1; j <= fac[i].second; j++)
			{
				diall += (ull)(j + 1)*(nowplus)-((ull)j*nowplus / fac[i].first);
				nowpow = nowpow + nowplus*nowplus;
				nowplus =nowplus*(ull) fac[i].first;
			}
			all = all*(nowpow + 1);
			all = all + nowpow;
			now *= diall;
		}
		all++;
		printf("%llu\n", all - now);
	}
}

//int main()
//{
//	int cot[200] = { 0 };
//	for (int i = 1; i <= 40; i++)
//	{
//		for (int j = 1; j <= i; j++)
//		{
//			for (int k = 1; k <= i; k++)
//			{
//				if ((k*j) % i == 0)cot[i]++;
//			}
//		}
//	}
//	for (int i = 1; i <= 40; i++)
//		cout << i << " " << cot[i] << endl;
//	sp;
//}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值