Description
给出 n n ,求,其中 σ0(x) σ 0 ( x ) 表示 x x 的因子数
Input
第一行一整数表示用例组数,每组用例输入一整数 n(1≤T≤104,1≤n≤1011) n ( 1 ≤ T ≤ 10 4 , 1 ≤ n ≤ 10 11 )
Output
输出 S(n) S ( n )
Sample Input
5
1
2
3
10
100
Sample Output
1
5
9
73
2302
Solution
显然 S(n) S ( n ) 为积性函数,且对于素数 p p 有,故直接用洲阁筛或者 min_25 m i n _ 25 筛,由于 S(p) S ( p ) 为 p p 的次多项式,只需维护区间素数个数即可
Code
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define maxn 700005
int p[maxn],f[maxn],np=0,m=350000;
void get_prime(int n)
{
for(int i=2;i<=n;i++)
{
if(!f[i])p[++np]=i;
for(int j=1;j<=np&&i*p[j]<=n;j++)
{
f[i*p[j]]=1;
if(i%p[j]==0)break;
}
}
np--;
}
ll val[maxn],n;
int nn,cnt;
void init()
{
nn=1;
while((ll)nn*nn<n)nn++;
cnt=0;
for(ll i=1;i<=n;i=n/(n/i)+1)val[++cnt]=n/i;
}
int ID(ll x)
{
if(x>=nn)return n/x;
return cnt-x+1;
}
int F(int p,int e)
{
return 3*e+1;
}
ll g0[maxn];
void Get_g(ll n)
{
for(int i=1;i<=cnt;i++)g0[i]=val[i]-1;
for(int j=1;j<=np;j++)
for(int i=1;i<=cnt&&(ll)p[j]*p[j]<=val[i];i++)
{
int k=ID(val[i]/p[j]);
g0[i]=g0[i]-(g0[k]-(j-1));
}
return ;
}
ll S(ll i,int j)
{
if(i<=1||p[j]>i)return 0;
int k=ID(i);
ll ans=4ll*(g0[k]-(j-1));
for(int k=j;k<=np&&(ll)p[k]*p[k]<=i;k++)
{
ll p1=p[k],p2=(ll)p[k]*p[k];
for(int e=1;p2<=i;p1=p2,p2*=p[k],e++)
ans+=S(i/p1,k+1)*F(p[k],e)+F(p[k],e+1);
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
get_prime(m);
while(T--)
{
scanf("%lld",&n);
init();
Get_g(n);
printf("%lldn",S(n,1)+1);
}
return 0;
}
最后
以上就是悲凉蜗牛最近收集整理的关于SPOJ 21174 DIVCNT3 - Counting Divisors (cube)(min_25筛)的全部内容,更多相关SPOJ内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复