分析
首先将1~100的所有素数找出来,之后将每个数进行质因数分解,找出其所有质因数的幂,之后将所有素数的幂次相乘,得到答案。
C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4+10;
int a[N],cnt,co[101];
void mul(int a[],int x) //高精度乘法
{
int t=N-1,temp=0;
while(a[t]==0) t--;
for(int i=0;i<=t;i++)
{
temp+=a[i]*x;
a[i]=temp%10;
temp/=10;
}
while(temp)
{
a[++t]=temp%10;
temp/=10;
}
for(int i=t;i>=0;i--) cout<<a[i];
cout<<endl;
}
bool st[101];
bool prime(int x) //判断素数
{
for(int i=2;i<=x/i;i++)
{
if(x%i==0) return false;
}
return true;
}
void getp(int n) //筛出所有素数
{
for(int i=2;i<=n;i++)
{
if(prime(i)) st[i]=1;
}
}
int divide(int x) //计算一个数的质因数的幂次
{
int tot=1,k=x;
for(int i=2;i<=x/i;i++)
{
int s=0;
while(x%i==0)
{
s++;
x/=i;
}
if(s)
{
co[i]+=s;
}
}
if(x>1)
{
co[x]++;
}
return tot;
}
int main()
{
getp(100);
a[0]=1;
for(int i=2;i<=100;i++)
{
divide(i);
}
for(int i=1;i<=100;i++)
{
if(st[i]) //将所有素数的幂次相乘
mul(a,co[i]+1);
}
return 0;
}