伯努利数

这个是答案

其中的b是伯努利数,可以n^2预处理

伯努利数n^2递推

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3 + , mod = 1e9 + ;
ll n, k;
ll inv[N], c[N][N], b[N];
inline ll rd()
{
ll x = , f = ;
char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = x * + c - ''; c = getchar(); }
return x * f;
}
int main()
{
int T = rd();
c[][] = ;
for(int i = ; i < N; ++i)
{
c[i][] = ;
for(int j = ; j < N; ++j) c[i][j] = (c[i - ][j] + c[i - ][j - ]) % mod;
}
inv[] = ;
for(int i = ; i < N; ++i)
if(i != ) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
b[] = ;
for(int i = ; i < N - ; ++i)
{
for(int j = ; j < i; ++j)
b[i] = (b[i] + c[i + ][j] * b[j]) % mod;
b[i] = ((b[i] * -inv[i + ] % mod) + mod) % mod;
}
while(T--)
{
n = rd() % mod;
k = rd();
ll ans = , fac = ;
for(int i = ; i <= k + ; ++i)
{
fac = fac * (n + ) % mod;
ans = (ans + c[k + ][i] * b[k + - i] % mod * fac % mod) % mod;
}
ans = (ans * inv[k + ]) % mod;
printf("%lld\n", ans);
}
return ;
}

51nod1228的更多相关文章

  1. 51nod1228 序列求和(自然数幂和)

    与UVA766 Sum of powers类似,见http://www.cnblogs.com/IMGavin/p/5948824.html 由于结果对MOD取模,使用逆元 #include<c ...

  2. 51nod1228 序列求和(伯努利数)

    题面 传送门 题解 \(O(n^2)\)预处理伯努利数 不知道伯努利数是什么的可以看看这篇文章 不过这个数据范围拉格朗日差值应该也没问题--吧--大概-- //minamoto #include< ...

  3. 51Nod - 1228 序列求和 (自然数幂和+伯努利数)

    https://vjudge.net/problem/51Nod-1228 Description T(n) = n^k,S(n) = T(1) + T(2) + ...... T(n).给出n和k, ...

随机推荐

  1. python(40)- 进程、线程、协程及IO模型

    一.操作系统概念 操作系统位于底层硬件与应用软件之间的一层.工作方式:向下管理硬件,向上提供接口. 操作系统进行进程切换:1.出现IO操作:2.固定时间. 固定时间很短,人感受不到.每一个应用层运行起 ...

  2. mysql创建还原点

    set autocommit = 0;   insert into t1(name) values ("user1"); savepoint p1;   insert into t ...

  3. CSS盒模型之三角形

    W3上介绍盒模型: 这里教程,但是太过于简单了,http://www.w3.org/community/webed/wiki/CSS/Training/Box_model. 如图,盒模型和背景属性控制 ...

  4. spring 接收_header 作为get请求的httpheader

    今天项目遇到一个问题,我们项目用户验证和权限验证的信息(licence)是在http头中设置的,百度了一下,只有ajax才能设置头信息,form表单是无法设置的,但是我突然想起springMVC关于f ...

  5. Java Web Start

    1. JNLP 2. Security issue: https://java.com/en/download/help/win_controlpanel.xml Windows 7, Vista C ...

  6. MacOS 修改主机名

    修改主机名 sudo scutil --set HostName xxx 修改共享名 sudo scutil --set ComputerName xxx

  7. 使用sed来自动注释/恢复crontab中的一个任务

    # 注释crontab任务crontab -l  >  ${WORK_DIR}/cron_binarysed  -i 's%\(.*/home/xyz/xyz.sh\)%#\1%' ${WORK ...

  8. android android:duplicateParentState=&quot;true&quot; &quot;false&quot;

    今天要做一个效果.组件RelativeLayout上有两个TextView.这两个TextView具有不同的颜色值,如今要的效果是,当RelativeLayout被点击时,整个item有高亮背景. 同 ...

  9. Unity3d 新建xml 读取xml

    在游戏开发中.Xml常常被用来作为技能配置.地图配置.人物动作配置等配置文件. Unity3d内置的Xml库让我们非常方便地就能够新建Xml和读取Xml. 以下是一个样例,新建了一个Xml文档.而且读 ...

  10. php 静态成员(static)抽象类(abstract)和接口(interface)

    首先看一下静态成员(static)和普通成员(public; protect; private)的区别: 静态成员是属于类的,普通成员是属于对象的: 例如: <?php header(" ...