题面

解题思路

手推可以得出,最后每个数字的贡献其实就是第n行杨辉三角数,然后直接卢卡斯直接算(今天才找到lucas定理时间复杂度是log n,log以模数为底)。代码略麻烦,不想改了。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long using namespace std;
const int MAXN = 1000005;
const int mod = 10007; int n,num;
LL inv[MAXN],to[MAXN];
LL ans; inline LL lucas(int n,int m){
if(n<m) return 0;
if(n<mod && m<mod) return to[n]*inv[m]%mod*inv[n-m]%mod;
return lucas(n%mod,m%mod)*lucas(n/mod,m/mod)%mod;
} int main(){
scanf("%d",&n);
if(n==0) {puts("0");return 0;}
if(n==1) {puts("1");return 1;}
to[1]=1;
for(register int i=2;i<=n;i++)
to[i]=to[i-1]*i%mod;
inv[mod-1]=mod-1;
for(register int i=mod-2;~i;i--)
inv[i]=inv[i+1]*(i+1)%mod;
num=2;
ans=3;
for(register int i=1;i<=(n/2)+1;i++){
LL k=lucas(n-1,i);
ans=(ans+(++num)*k%mod)%mod;
if(num==n) break;
ans=(ans+(++num)*k%mod)%mod;
if(num==n) break;
}
printf("%lld",ans);
return 0;
}

最新文章

  1. iOS-屏幕适配-UI布局
  2. centos7 firewall 防火墙
  3. ORA-01501: CREATE DATABASE failed
  4. Entity Framework 之Database first(数据库优先)&amp;Model First(模型优先)
  5. 混合高斯模型和EM
  6. ShortestPath:Six Degrees of Cowvin Bacon(POJ 2139)
  7. .net 后台设置meta的属性(keywords,description)
  8. 在Android中使用并发来提高速度和性能
  9. java jvm学习笔记七(jar包的代码认证和签名)
  10. android颜色对应的xml配置值,颜色表
  11. JavaScript高级程序设计17.pdf
  12. ORACLE 热备begin backup / end backup
  13. eclipse 发布web工程,修改tomcat端口
  14. BZOJ 3512: DZY Loves Math IV [杜教筛]
  15. Python_语法和界面设计
  16. 痞子衡嵌入式:ARM Cortex-M内核MCU开发那些事 - 索引
  17. mysql8.0 Server 在Windows平台中的安装、初始化和远程访问设置
  18. Python if __name__ == '__main__':(以主程序形式执行)
  19. codeforces 982A Row
  20. C++ 方阵原地旋转90度

热门文章

  1. csp-s模拟测试86
  2. 新建mapping
  3. 分享一份Java架构师学习资料,2019年最新整理!
  4. 第三周课堂笔记1thand2thand3th
  5. 面试系列24 dubbo负载均衡策略和集群容错策略
  6. MySQL5.1的安装过程
  7. Spark历险记之编译和远程任务提交
  8. Activiti表单(Form key)
  9. Amazon S3和EBS的区别
  10. python库参考学习网址