题目所谓的序列长度实际上就是各循环节的lcm+1.

所以题目等价于求出 一串数之和等于n,这串数的lcm种数。

由唯一分解定理可以联想到只要把每个素数的幂次放在一个分组里,然后对整体做一遍分组背包就行了。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF (LL)<<
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... int pri[N];
LL dp[N][N]; void init(int n)
{
mem(pri,);
FOR(i,,n) {
if (!pri[i]) pri[++pri[]]=i;
for (int j=; j<=pri[]&&pri[j]<=n/i; ++j) {
pri[pri[j]*i]=;
if (i%pri[j]==) break;
}
}
}
int main ()
{
int n;
scanf("%d",&n);
init(n);
FOR(i,,n) dp[][i]=;
FOR(i,,pri[]) FOR(j,,n) {
dp[i][j]=dp[i-][j];
for (int k=pri[i]; k<=j; k*=pri[i]) dp[i][j]+=dp[i-][j-k];
}
printf("%lld\n",dp[pri[]][n]);
return ;
}
05-27 23:10