题目
思路
这是here的简化版,把m换成了2
注意long long
code:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
long long a[80],ans,n,b[80];
long long ksm(long long x,long long y)
{
long long s=1;
while (y)
{
if (y&1) s=s*x%997;
x=x*x%997;
y>>=1;
}
return s;
}
long long gcd(long long x,long long y)
{
long long r=x%y;
while (r!=0)
{
x=y,y=r,r=x%y;
}
return y;
}
void dfs(long long tot,long long syg,long long s)
{
if (s==0)
{
long long x=0,y=1;
for (int i=1,j=1;i<tot;i++)
{
j=1;
x+=b[i]>>1;
while (j<i)
{
x+=gcd(b[i],b[j]);
j++;
}
y=y*b[i]%997;
}
for (int i=1,j=1;i<tot;i=j)
{
while (b[i]==b[j]&&j<tot) j++;
y=y*a[j-i]%997;
}
ans=(ans+ksm(2,x)*ksm(y,995)%997)%997;
return;
}
for (int i=syg;i<=s;i++)
{
b[tot]=i;
dfs(tot+1,i,s-i);
}
return;
}
int main()
{
cin>>n;
a[0]=1;
for (int i=1;i<=80;i++) a[i]=a[i-1]*i%997;
ans=0;
dfs(1,1,n);
cout<<ans;
return 0;
}