提高+省选-专题[数论][分解质因数]:P4167 [Violet]樱花
题目
华丽的分割线
解析
化简
对于含有二次项
则
若
换句话说,就是求有多少正整数
质因数分解
对于
则这个值为
复杂度为
大约为
注意
开始用筛出的素数去质因数分解,复杂度约为
代码
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
void read(int &x)
{
x=0;
int f;
f=1;
char c;
c=getchar();
while((c<'0'||c>'9')&&c!='-')
{
c=getchar();
}
if(c=='-')
{
f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<3)+(x<<1)+(c^48);
c=getchar();
}
x=x*f;
}
void read(ll &x)
{
x=0;
ll f;
f=1;
char c;
c=getchar();
while((c<'0'||c>'9')&&c!='-')
{
c=getchar();
}
if(c=='-')
{
f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<3)+(x<<1)+(c^48);
c=getchar();
}
x=x*f;
}
int prime[1010000],ptot;
const ll p=1e9+7;
bool is_prime[1010000];
void getprime(int n)
{
ptot=0;
is_prime[1]=1;
int i,j;
for(i=2;i<=n;i++)
{
if(is_prime[i]==0)
{
ptot++;
prime[ptot]=i;
}
for(j=1;j<=ptot&&prime[j]*i<=n;j++)
{
is_prime[prime[j]*i]=1;
if(i%prime[j]==0)
{
break;
}
}
}
}
int num[1010000],numtot;
inline int max(int x1,int x2)
{
return x1>x2 ? x1 : x2;
}
int main()
{
ll n,i,tmp,ans;
read(n);
if(n==1)
{
printf("1");
return 0;
}
getprime(n+100);
numtot=-0x3f3f3f3f;
for(i=1;i<=ptot&&prime[i]<=n;i++)
{
tmp=prime[i];
numtot=max(numtot,prime[i]);
while(tmp<=n)
{
num[prime[i]]+=n/tmp;
tmp*=prime[i];
}
}
ans=1;
for(i=1;i<=ptot&&prime[i]<=numtot;i++)
{
ans=ans*(num[prime[i]]*2+1)%p;
}
printf("%lld",(ans%p+p)%p);
}