sduT 2605-A^X mod P(大幂分解求和)
来源:互联网 发布:剑灵捏脸数据导入图 编辑:程序博客网 时间:2024/06/05 12:05
A^X mod P
Time Limit: 5000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
It's easy for ACMer to calculate A^X mod P. Now given seven integers n, A, K, a, b, m, P, and a function f(x) which defined as following.
f(x) = K, x = 1
f(x) = (a*f(x-1) + b)%m , x > 1
Now, Your task is to calculate
( A^(f(1)) + A^(f(2)) + A^(f(3)) + ...... + A^(f(n)) ) modular P.
输入
In the first line there is an integer T (1 < T <= 40), which indicates the number of test cases, and then T test cases follow. A test case contains seven integers n, A, K, a, b, m, P in one line.
1 <= n <= 10^6
0 <= A, K, a, b <= 10^9
1 <= m, P <= 10^9
输出
For each case, the output format is “Case #c: ans”.
c is the case number start from 1.
ans is the answer of this problem.
示例输入
23 2 1 1 1 100 1003 15 123 2 3 1000 107
示例输出
Case #1: 14Case #2: 63
提示
来源
2013年山东省第四届ACM大学生程序设计竞赛
题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2605
思路:第一眼看上去,我糙,赤裸裸的一个快速幂,兴冲冲地去写了发,结果超时了\(^o^)/\(^o^)/\(^o^)/\(^o^)/
结果看了大神的博客之后,秒懂,居然是恶心得打表。
好吧,万恶的打表题,我的确不太会相关的一些应用。
此处每个f[i]表示成如下形式;
f[i]=a*333333+b;
把这两部分打表出来不就ok了嘛;
TMD,当时智障了一下
代码:
题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2605
思路:第一眼看上去,我糙,赤裸裸的一个快速幂,兴冲冲地去写了发,结果超时了\(^o^)/\(^o^)/\(^o^)/\(^o^)/
结果看了大神的博客之后,秒懂,居然是恶心得打表。
好吧,万恶的打表题,我的确不太会相关的一些应用。
此处每个f[i]表示成如下形式;
f[i]=a*333333+b;
把这两部分打表出来不就ok了嘛;
TMD,当时智障了一下
代码:
#include<stdio.h>#include<string.h>#include <iostream>#include<algorithm>using namespace std;const int maxn=1111111;const int xun=333333;const int mod=2012;typedef long long ll;ll f[maxn];ll db[maxn],dbs[maxn];int main(){ int T,n,A,K,a,b,m,P; scanf("%d",&T); for(int t=1;t<=T;t++) { cin>>n>>A>>K>>a>>b>>m>>P; f[1]=K; db[0]=dbs[0]=1; for(int i=1;i<=xun;i++) db[i]=(db[i-1]*A)%P; dbs[1]=db[xun]; for(int i=2;i<=xun;i++) dbs[i]=dbs[i-1]*dbs[1]%P; ll res=dbs[f[1]/xun]*db[f[1]%xun]%P; res%=P; for(int i=2;i<=n;i++) { f[i]=f[i-1]*a+b; f[i]%=m; res+=dbs[f[i]/xun]*db[f[i]%xun]%P; } res%=P; cout<<"Case #"<<t<<": "<<res<<endl; } return 0;}
1 0
- SDUT 2605-A^X mod P(大幂分解求和)
- sduT 2605-A^X mod P(大幂分解求和)
- A^X mod P 大幂分解求和 打表
- sdut 2605 A^X mod P (分解优化)
- SDUT 2605 A^X mod P
- sdut 2605 预处理A^N mod p
- A^X mod P
- A^X mod P
- A^X mod P
- UPC2219: A^X mod P
- C:A^X mod P
- 1038 X^A Mod P
- 第四届 山东省ACM A^X mod P (分解优化=哈希+打表)
- 第四届acm A^X mod P
- sdut2605——A^X mod P
- 51Nod-1038-X^A Mod P
- hdu 3930 X^N=a(mod) p 求X
- X^2 Mod P
- OC_复制内容到粘贴板
- c++作业4
- robots.txt 不让搜索引擎收录网站的方法
- POJ2385-Apple Catching
- Android开发之6.0运行时权限处理
- sduT 2605-A^X mod P(大幂分解求和)
- Object-c------类的声明与实现以及注意事项
- cf655A Buses Between Cities
- 计数排序
- git commit合并
- [UVa 11889] Benefit (基础数论+GCD+LCM)
- 进程同步---生产者与消费者问题以及进程同步机制--信号量及P、V操作
- JS数据结构与算法--字典
- Android开发艺术探索——第四章View的工作原理