标签:pre pac fclose 思考 include png i+1 image end
n<=20
有♂趣的题目
n个数,上限为n!,可以想到每次用第i个数来进行i!级别的约束
简单思考一下,发现每次可以把m变到n!*1/i!以内
那么每次减掉的数就是n!*(1i-1)/i!,即(1i-1)*Π(i+1)~n,显然是n!的约数
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;
int n,i,j,k,l;
ll m,s;
int main()
{
#ifdef file
freopen("uoj82.in","r",stdin);
#endif
scanf("%d",&n);
scanf("%lld",&m);
s=1;fo(i,1,n) s*=i;
i=2;
while (m)
{
if (m>=s) printf("%lld\n",(m/s)*s);
m%=s,s/=i,++i;
}
fclose(stdin);
fclose(stdout);
return 0;
}
标签:pre pac fclose 思考 include png i+1 image end
原文地址:https://www.cnblogs.com/gmh77/p/12940974.html