F. Product transformation
来源:互联网 发布:淘宝2元包邮怎么挣钱 编辑:程序博客网 时间:2024/06/06 19:35
嗯,序列写一写可以发现,从最后面开始相邻的差都是杨辉三角。然后走到头,前面还有剩余的话就是
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 107;const int MAXN = 1e6+7;LL n,m,a,q;LL quick_mod(LL a,LL b,LL mod){ LL ans = 1,base = a%mod; while(b) { if(b & 1)ans = ans*base%mod; base = base*base%mod; b >>= 1; } return ans;}LL num[MAXN],two[MAXN];void init(LL mod){ num[1] = 1; for(LL i = 2; i <= m; ++i) { num[i] = num[i-1]*i%mod; } two[0] = 1; for(LL i = 1; i <= n; ++i) { two[i] = two[i-1]*2%mod; }}LL C(LL n,LL m,LL mod){ LL ans = num[n]; ans = ans*quick_mod(num[m],mod-2,mod)%mod; ans = ans*quick_mod(num[n-m],mod-2,mod)%mod; return ans;}LL ans[MAXN];int main(){ scanf("%I64d%I64d%I64d%I64d",&n,&m,&a,&q); LL mod = 1; LL x = a; for(;; mod++) { x %= q; if(x == 1)break; x *= a; } init(mod); LL i; ans[n] = 1; for(i = n-1; i >= 1; --i) { LL p = n-i; if(p == m)break; ans[i] = (ans[i+1] + C(m,p,mod))%mod; } for(; i >= 1; --i)ans[i] = two[m]; //for(int i = 1; i <= n; ++i)printf("%I64d\n",ans[i]); for(int i = 1; i <= n; ++i) { ans[i] = quick_mod(a,ans[i],q); } for(int i = 1; i <= n; ++i)printf("%I64d ",ans[i]); return 0;}
阅读全文
0 0
- F. Product transformation
- codeforces 852F Product transformation(数学)
- Appendix F Homogeneous Coordinates and Transformation Matrices
- Transformation
- product
- Product
- Product
- Product
- Product
- 目录F:\oracle\product\10.2.0\db_1\NETWORK\ADMIN 下没有tnsnames.ora配置文件
- “ORA-01110: data file 1: 'F:\oracle\product\10.2.0\oradata\orcl\sysaux01.dbf'"解决方法
- Cannot add or update a child row: a foreign key constraint fails (`tsproduct/product`, CONSTRAINT `F
- f
- f
- f
- f
- f
- F#
- Windows下安装并设置Redis
- cache policy
- 如何在小程序的js中获取当前脚本的路径或名称
- 2015 ACM/ICPC Asia Regional Shenyang OnlineHDU-5458 Stability
- 技术文章 | Javascript 文件命名规范
- F. Product transformation
- hdu6205(尺取)
- Maven的pom.xml文件结构详解
- 按钮背景图片更换
- 303. Range Sum Query
- 短实习---java数组(基础知识)
- Python3.5 email发送邮件,包含txt、图片、HTML、附件
- 鸡蛋栈
- Apache POI实现数据的Excel导出