Description

A young schoolboy would like to calculate the sum


for some fixed natural k and different natural n. He observed that calculating ik
for all i (1<=i<=n) and summing up results is a too slow way to
do it, because the number of required arithmetical operations increases
as n increases. Fortunately, there is another method which takes only a
constant number of operations regardless of n. It is possible to show
that the sum Sk(n) is equal to some polynomial of degree k+1 in the variable n with rational coefficients, i.e.,



We require that integer M be positive and as small as possible. Under this condition the entire set of such numbers (i.e. M, ak+1, ak, ... , a1, a0)
will be unique for the given k. You have to write a program to find
such set of coefficients to help the schoolboy make his calculations
quicker.

Input

The input file contains a single integer k (1<=k<=20).

Output

Write integer numbers M, ak+1, ak, ... , a1, a0
to the output file in the given order. Numbers should be separated by
one space. Remember that you should write the answer with the smallest
positive M possible.

Sample Input

2

Sample Output

6 2 3 1 0

Source

【分析】
题意就是给出一个k,找一个最小的M使得中a[i]皆为整数.
这个涉及到伯努利数的一些公式,如果不知道的话基本没法做..

1. 伯努利数与自然数幂的关系:

2. 伯努利数递推式:

先通过递推式求得伯努利数,然后用1公式并将中间的(n+1) ^ i,变成n ^ i,后面再加上n ^ k,化进去就行了。

 /*
宋代朱敦儒
《西江月·世事短如春梦》
世事短如春梦,人情薄似秋云。不须计较苦劳心。万事原来有命。
幸遇三杯酒好,况逢一朵花新。片时欢笑且相亲。明日阴晴未定。
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <iostream>
#include <string>
#include <ctime>
#define LOCAL
const int MAXN = + ;
const double Pi = acos(-1.0);
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){return b == ? a: gcd(b, a % b);}
struct Num{
ll a, b;//分数,b为分母
Num(ll x = , ll y = ) {a = x;b = y;}
void update(){
ll tmp = gcd(a, b);
a /= tmp;
b /= tmp;
}
Num operator + (const Num &c){
ll fz = a * c.b + b * c.a, fm = b * c.b;
if (fz == ) return Num(, );
ll tmp = gcd(fz, fm);
return Num(fz / tmp, fm / tmp);
}
}B[MAXN], A[MAXN];
ll C[MAXN][MAXN]; void init(){
//预处理组合数
for (int i = ; i < MAXN; i++) C[i][] = C[i][i] = ;
for (int i = ; i < MAXN; i++)
for (int j = ; j < MAXN; j++) C[i][j] = C[i - ][j] + C[i - ][j - ];
//预处理伯努利数
B[] = Num(, );
for (int i = ; i < MAXN; i++){
Num tmp = Num(, ), add;
for (int j = ; j < i; j++){
add = B[j];
add.a *= C[i + ][j];
tmp = tmp + add;
}
if (tmp.a) tmp.b *= -(i + );
tmp.update();
B[i] = tmp;
}
}
void work(){
int n;
scanf("%d", &n);
ll M = n + , flag = , Lcm;
A[] = Num(, );
for (int i = ; i <= n + ; i++){
if (B[n + - i].a == ) {A[i] = Num(, );continue;}
Num tmp = B[n + - i];
tmp.a *= C[n + ][i];//C[n+1][i] = C[n + 1][n + 1 - i]
tmp.update();
if (flag == ) Lcm = flag = tmp.b;
A[i] = tmp;
}
A[n] = A[n] + Num(n + , ); for (int i = ; i <= n + ; i++){
if (A[i].a == ) continue;
Lcm = (Lcm * A[i].b) / gcd(Lcm, A[i].b);
}
if (Lcm < ) Lcm *= -;
M *= Lcm;
printf("%lld", M);
for (int i = n + ; i >= ; i--) printf(" %lld", A[i].a * Lcm / A[i].b);
} int main(){ init();
work();
//printf("%lld\n", C[5][3]);
return ;
}

最新文章

  1. CSS中box-sizing属性的理解与部分用法
  2. {Reship}{KMP字符串匹配}
  3. 关于Linux 下 Mysql 远程访问时出现的Access denied for user &#39;用户名&#39;@&#39;IP地址&#39; (using password:NO)
  4. PWM波控制舵机总结
  5. 【编程题目】有两个序列 a,b,大小都为 n,序列元素的值任意整数,无序;(需要回头仔细研究)
  6. UVa1515 Pool construction(最小割)
  7. static的本质
  8. C#中的yield return与Unity中的Coroutine(协程)(上)
  9. Android findBugs
  10. 在Windows Server2008R2中导入Excel不能使用Jet 4.0的解决方法
  11. SQL Server 函数执行
  12. Node.js中的异步I/O是如何进行的?
  13. centos7下关闭sshd的tcp6
  14. Yii2 mysql查询 int自动变string解决办法
  15. iOS高效裁剪图片圆角算法
  16. linux crontab详解 php开发相关
  17. ORACLE中使用row_number over()排序
  18. activiti发布APP时报错:关联的流程无效
  19. Jmeter(二十二)_脚本上传Gitlab
  20. SQL Server 2008中的Hints(提示)的简单整理

热门文章

  1. Semi-definite programming优化工具
  2. 虚拟机之仅主机模式(HostOnly)链接外网设置
  3. 转载:Java多线程中join方法的理解
  4. patch与diff的恩怨
  5. 是C太傻逼?还是C++不够傻逼;
  6. Android开发之50个常见实用技巧——活用布局
  7. Unity3D延迟回调的封装
  8. LCD深度剖析
  9. oracle3
  10. Flume NG中的ElasticSearch Sink