2013年省赛H题
你不能每次都快速幂算A^x,优化就是预处理,把10^9预处理成10^5和10^4。
想法真的是非常巧妙啊
N=100000
构造两个数组,f1[N],间隔为A
f2[1e4]间隔为A^N,中间用f1来填补
f[x]=f1[x%N]*f2[x/N]%P;

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100000
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
long long T,ans,cnt;
long long n,A,K,a,b,m,P;
long long f1[],f2[],f[]; void in(long long &x){
long long y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(long long x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} void predeal(){
f1[]=f2[]=;
For(i,,N)
f1[i]=f1[i-]*A%P;
For(i,,1e4)
f2[i]=f2[i-]*f1[N]%P;
} int main(){
in(T);
while(T--){
in(n);in(A);in(K);in(a);in(b);in(m);in(P);
predeal();
f[]=K;
For(i,,n)
f[i]=(a*f[i-]+b)%m;
ans=;
For(i,,n){
ans+=f1[f[i]%N]*f2[f[i]/N]%P;
ans%=P;
}
cout<<"Case #"<<++cnt<<": "<<ans<<endl;
}
return ;
}

2013年省赛H题的更多相关文章

  1. 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)

    Hypersphere Time Limit: 1 Second       Memory Limit: 32768 KB In the world of k-dimension, there's a ...

  2. hdu 4788 (2013成都现场赛 H题)

    100MB=10^5KB=10^8B 100MB=100*2^10KB=100*2^20B Sample Input2100[MB]1[B] Sample OutputCase #1: 4.63%Ca ...

  3. 2013年山东省赛F题 Mountain Subsequences

    2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...

  4. 2013年省赛I题 Thrall’s Dream

    2013年省赛I题判断单向联通,用bfs剪枝:从小到大跑,如果遇到之前跑过的点(也就是编号小于当前点的点),就o(n)传递关系. bfs #include<iostream> #inclu ...

  5. HDU 4816 Bathysphere (2013长春现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

  6. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)

    Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

  9. HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. vue 中监测滚动条加载数据(懒加载数据)

    vue 中监测滚动条加载数据(懒加载数据) 1:钩子函数监听滚动事件: mounted () { this.$nextTick(function () { window.addEventListene ...

  2. 关于FastDBF库读写ArcGis dbf文件的小bug

    该库托管于GitHub,地址:https://github.com/SocialExplorer/FastDBF 贡献者应该都是老外,所以…… 1.解析文件头,字段名部分如果有中文命名字段会出错 在D ...

  3. VS.NET C# 开发ArcGis插件无法进入断点调试的解决方法

    有人问起,想起来码到这儿,再有人问可以直接给链接参考. 以10.1为例,因为博主一直用的它,所以只能是这个例.其他版本如有不同,那就不同吧. 首先,得确认调试时启动了外部程序 在项目属性→调试→启动外 ...

  4. CSS部分语法2

    <!-- 第1部分 尺寸与框模型 略 第2部分背景设置 2.1 背景颜色:background-color:value 2.2 背景图片:background-image body{ backg ...

  5. Mac平台Clion配置GLFW+GLAD的项目

    前期的准备工作详见LearnOpenGL CN 看这篇教程的前提是假设你已经编译好了GLFW文件夹以及下载好了GLAD,不会的话可以看我的另一篇 文章的前部分: 配置 Clion新建一个项目,CMak ...

  6. python接收axios的post请求,并处理后返回数据

    公司的python工程师不会js和python数据交互,所以我就去试了一下. 首先安装python,django框架和django-cors-headers. python官网下载,按提示操作,记住最 ...

  7. (八)python中的函数

    一.聊聊函数 1.什么是函数? 上学时我记得最简单的是 F=x+y 这是一个简单的函数,看看python 中的格式 def test(): #函数定义 def 万年不变 print("> ...

  8. 【bzoj 4833】[Lydsy1704月赛]最小公倍佩尔数

    Description 令 $(1+\sqrt 2)^n=e(n)+\sqrt 2\cdot f(n)$ ,其中 $e(n),f(n)$ 都是整数,显然有 $(1-\sqrt 2)^n=e(n)-\s ...

  9. jpa Auditor 自动赋值与自定义 @CreatedBy @LastModifiedBy @CreatedDate @LastModifiedDate

    在spring jpa audit 中,在字段或者方法上使用注解@CreatedDate.@CreatedBy.@LastModifiedDate.@LastModifiedBy,当进行实体插入或者更 ...

  10. git出现refusing to merge unrelated histories

    问题描述当本地分支与远程分支没有共同祖先时,会出现 fatal: refusing to merge unrelated histories 的问题. 解决方案可以使用 rebase 的方式来进行合并 ...