# HDU 5528 Count a * b(数论)

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

#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;
//}

• 本文已收录于以下专栏：

举报原因： 您举报文章：HDU 5528 Count a * b(数论) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)