博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
51nod-1228: 序列求和
阅读量:4581 次
发布时间:2019-06-09

本文共 965 字,大约阅读时间需要 3 分钟。

【传送门:】


简要题意:

  求出$\sum_{i=1}^{n}i^{k}\mod p$


题解:

  因为有多组数据,所以不能用差分表做

  要用伯努利数来做(学了一上午。。)

  伯努利数,$B_{0}=1$

  因为$\sum_{j=0}^iC_{i+1}^jB_j=0$

  所以$B_i=-\frac{1}{i+1}\sum_{j=0}^{i-1}C_{i+1}^{j}B_j$

  预处理B数组

  对于每个n,k,答案为$\sum_{i=1}^{n}i^k={1\over{k+1}}\sum_{i=1}^{k+1}C_{k+1}^i*B_{k+1-i}*(n+1)^i$


参考代码:

#include
#include
#include
#include
#include
using namespace std;typedef long long LL;LL Mod=1e9+7;LL ny[2100],jc[2100],B[2100];LL C(int n,int m){ return jc[n]*ny[m]%Mod*ny[n-m]%Mod;}LL p_mod(LL a,int b){ LL ans=1; while(b!=0) { if(b%2==1) ans=ans*a%Mod; a=a*a%Mod;b/=2; } return ans;}int main(){ ny[0]=1;jc[0]=1; for(int i=1;i<=2000;i++) jc[i]=jc[i-1]*i%Mod,ny[i]=p_mod(jc[i],Mod-2); B[0]=1; for(int i=1;i<=2000;i++) { B[i]=0; for(int j=0;j

 

转载于:https://www.cnblogs.com/Never-mind/p/9809459.html

你可能感兴趣的文章
一些多项式的整理
查看>>
NIO selector
查看>>
MySQL中DATETIME、DATE和TIMESTAMP类型的区别
查看>>
asp代码获取年数,季度数.星期数,天数,小时数,分钟数,秒数等时
查看>>
python之建完model之后操作admin
查看>>
Java 类加载机制 ClassLoader Class.forName 内存管理 垃圾回收GC
查看>>
shell 脚本后台运行知识
查看>>
php设置cookie,在js中如何获取
查看>>
实验三+099+吴丹丹
查看>>
[bzoj3036]绿豆蛙的归宿
查看>>
[洛谷P5057][CQOI2006]简单题
查看>>
多线程同步的几种方法
查看>>
数据结构-冒泡排序
查看>>
关于程序状态字寄存器PSW(Program Status Word)与多核多线程
查看>>
mybatis的缓存
查看>>
java 缓冲流 Buffer
查看>>
7月23号=》261页-265页
查看>>
软考知识点梳理--综合布线
查看>>
Mysql5.6主从热备配置
查看>>
VS2010DebugView捕捉
查看>>