# POJ3604 Professor Ben[线性筛/暴力]

## Professor Ben

POJ - 3604

void initial()
{
sum[1]=1;
for (int i=2 ; i<N ; ++i)
{
for (int j=i ; j<N ; j+=i)
{
d[j]++;
sum[j]+=(d[j]+1)*(d[j]+1)*(d[j]+1);
}
}
}

http://blog.miskcoo.com/2014/09/power-sum

====================================================================

sum[i]就是 i 的结果

num[i]就是 i 的最小素因子的个数

① n 是素数

sum[i]=1+8;

num[i]=1;

② i % prim[j] != 0

(因为每次扫的必然是最小素因子，至于为什么，本身线性筛就是被最小素因子筛出来的)

③ i % prim[j] == 0

[OTL 再一次知道线性筛的厉害啊]

#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int N=5e6+5;
int prim[N],num[N],sum[N];
bool mark[N];
int cnt;
int s3(int x)
{
return (x+1)*(x+1)*(x+2)*(x+2)/4;
}
void initial()
{
cnt=0;
sum[1]=1;
for (int i=2 ; i<N ; ++i)
{
if (!mark[i])
{
prim[cnt++]=i;
num[i]=1;
sum[i]=9;
}
for (int j=0 ; j<cnt && i*prim[j]<N ; ++j)
{
mark[i*prim[j]]=1;
if (!(i%prim[j]))
{
num[i*prim[j]]=num[i]+1;
sum[i*prim[j]]=sum[i]/s3(num[i])*s3(num[i*prim[j]]);
break;
}
sum[i*prim[j]]=sum[i]*sum[prim[j]];
num[i*prim[j]]=1;
}
}
}
int main()
{
initial();
int T;
scanf("%d",&T);
while (T--)
{
int n;
scanf("%d",&n);
printf("%d\n",sum[n]);
}
return 0;
}

#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int N=1e4+5;
bool mark[N];
int prim[N];
int num[N];
int cnt;
void initial()
{
cnt=0;
for (int i=2 ; i<N ; ++i)
{
if (!mark[i])
prim[cnt++]=i;
for (int j=0 ; j<cnt && i*prim[j]<N ; ++j)
{
mark[i*prim[j]]=1;
if (!(i%prim[j]))
break;
}
}
}
ll divi(int n)
{
int k=0;
ll ans=1;
for (int i=0 ; i<cnt ; ++i)
{
if (prim[i]*prim[i]>n)
break;
if (!(n%prim[i]))
{
int ch=0;
while (!(n%prim[i]))
{
ch++;
n/=prim[i];
}
ans*=(ch+1)*(ch+1)*(ch+2)*(ch+2)/4;
}
}
if (n>1)
ans*=(1+8);
return ans;
}
int main()
{
initial();
int T;
scanf("%d",&T);
while (T--)
{
int n;
scanf("%d",&n);
printf("%lld\n",divi(n));
}
return 0;
}