Educational Codeforces Round 13 Iterated Linear Function(数学)
来源:互联网 发布:淘宝开店怎么上传宝贝 编辑:程序博客网 时间:2024/04/28 20:47
思路:推一下公式可以知道其实就是a^n*x+a^(n-1)*b+a^(n-2)*b+....b,就是一个等比数列求和嘛,注意特判1,可是因为范围太大,所以就要用到模乘法以及逆元。
a^(mod) % mod = a
a^(mod-1) % mod = 1
a^(mod-2) * a %mod = 1
所以a^(mod-2)是a的逆元,这样就可以将等比数列求和里面的除给变成乘法了
#include<bits\stdc++.h>using namespace std;#define LL long longconst LL mod = 1e9+7;LL quickpow(LL m,LL n,LL k){ LL b = 1; while(n>0) { if(n&1) b = (b*m)%k; n>>=1; m = (m*m)%k; } return b;}int main(){ LL a,b,n,x; cin >> a >> b >> n >> x; if(a==1) { cout << (x+(n%mod*b))%mod << endl; } else { LL ans = (quickpow(a,n,mod)-1+mod)%mod; ans = ans *quickpow(a-1,mod-2,mod)%mod*b%mod;ans = (ans+quickpow(a,n,mod)*x+mod)%mod;cout << ans << endl; }}
0 0
- Educational Codeforces Round 13 Iterated Linear Function(数学)
- Educational Codeforces Round 13-D. Iterated Linear Function
- Educational Codeforces Round 13——D. Iterated Linear Function(矩阵快速幂或普通快速幂水题)
- Educational Codeforces Round 13 D. Iterated Linear Function 逆元+公式+费马小定理
- Educational Codeforces Round 13 D. Iterated Linear Function 逆元+公式+费马小定理
- Educational Codeforces Round 13 D. Iterated Linear Function 逆元+公式+费马小定理_1
- Codeforces-678D-Iterated Linear Function
- codeforces_678D. Iterated Linear Function(快速幂)
- Iterated Linear Function
- Iterated Linear Function
- Educational Codeforces Round 26 E. Vasya's Function 数学,迭代法
- Educational Codeforces Round 13 C Joty and Chocolate(数学)
- Educational Codeforces Round 7(A)数学
- Codeforces 678 D. Iterated Linear Function(构造矩阵)
- CodeForces 678D Iterated Linear Function 矩阵快速幂
- Educational Codeforces Round 13
- Educational Codeforces Round 13
- Educational Codeforces Round 5 E. Sum of Remainders(数学)
- sql语句
- Hello World 第一个程序
- 静态代码块 构造代码块 构造函数 区别
- C 指针用法辨析及汇总
- 设置UItextfiled的placehold的颜色和大小
- Educational Codeforces Round 13 Iterated Linear Function(数学)
- Git工作区和暂存区介绍
- mysql学习经验
- 本萌E助手的最新动态
- 增强型P沟道mos管(如si2333ds)开关条件
- 修改/etc/profile文件后不能使用linux命令
- Struts2 拦截器处理同步(普通Http)请求和异步(post,ajax)请求时拦截配置
- 剪辑板例子,文本、图片、文件都有嗷
- 易语言静态编译链接器大全(为EIDE助手准备滴)