UOJ #82. 【UR #7】水题生成器
发现任意一个 \(\leq n!\) 的数 \(x\) 都可以表现为以下形式:
\[x=a_1\times \frac{n!}{1!}+a_2\times \frac{n!}{2!}+\cdots + a_n\times \frac{n!}{n!}
\]
且 \(a_i\leq i\)。直接输出 \(a_i\times \frac{n!}{i!}\) 就行了。
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n, m;
void init()
{
scanf("%lld %lld", &n, &m);
}
void work()
{
LL fac = 1;
for (int i = 1; i <= n; i++)
fac=fac * i;
for (int i = 1; i <= n; i++)
{
fac /= i;
LL k = m / fac * fac;
if (k)
printf("%lld\n", k);
m -= k;
}
}
int main()
{
init();
work();
return 0;
}
由于博主比较菜,所以有很多东西待学习,大部分文章会持续更新,另外如果有出错或者不周之处,欢迎大家在评论中指出!