伯努利数

这个是答案

其中的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. java中Volatile修饰符的含义

    在java语言中:为了获得最佳速度,同意线程保存共享成员变量的私有拷贝.并且仅仅当线程进入或者离开同步代码块时才与共享成员变量的原始值进行对照. volatilekeyword的作用就是提示vm:对于 ...

  2. 2.nginx整合PHP

    /usr/local/src/下都有什么:.tar.gz文件和解压之后的源码 /usr/local/下都有什么:源码编译之后的东西 安装mysql客户端 安装mysql服务端 启动mysql服务端 s ...

  3. AtomicInteger在实际项目中的应用

    AtomicInteger.一个提供原子操作的Integer的类. 在Java语言中,++i和i++操作并非线程安全的.在使用的时候,不可避免的会用到synchronized关键字. 而AtomicI ...

  4. Controller//控制器

    #include<opencv2\core\core.hpp> #include<opencv2\imgproc\imgproc.hpp> #include<opencv ...

  5. poj 1703 Find them, Catch them(种类并查集和一种巧妙的方法)

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36176   Accepted: ...

  6. 关于erlang的向上取整和向下取整

    在erlang的API中,erlang:trunc/1 是就近取整,erlang:round/1是四舍五入的, 整理下:对于正数的向上和向下取整, %% 向上取整 ceil(N) -> T = ...

  7. PythonCookBook笔记——数据编码和处理

    数据编码和处理 主要涉及用Python处理不同方式编码的数据,如CSV.JSON.XML和二进制包装记录. 读写CSV数据 使用csv库. import csv with open('stocks.c ...

  8. 07 http内容压缩

    一:http内容压缩 思考: Content-Length在之前的学习中,我们知道,代表返回的主体的长度 但此处,为什么返回的主体长度和content-length不一致呢? 原因在于: Conten ...

  9. android handler looper

    http://www.cnblogs.com/plokmju/p/android_Handler.html

  10. [转]***换机房换ip之后不能连外网

    ***换机房换ip之后不能连外网 时间 2015-07-21 15:17:16  Wendal随笔 原文  http://wendal.net/2015/07/21.html 主题 iptables ...