2013年省赛H题
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题的更多相关文章
- 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)
Hypersphere Time Limit: 1 Second Memory Limit: 32768 KB In the world of k-dimension, there's a ...
- 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 ...
- 2013年山东省赛F题 Mountain Subsequences
2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...
- 2013年省赛I题 Thrall’s Dream
2013年省赛I题判断单向联通,用bfs剪枝:从小到大跑,如果遇到之前跑过的点(也就是编号小于当前点的点),就o(n)传递关系. bfs #include<iostream> #inclu ...
- HDU 4816 Bathysphere (2013长春现场赛D题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...
- 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 ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 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 ...
- HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- express session 和 socketio session关联
express session http是没有状态的协议, 需要web框架自己实现会话和会话管理工作. express框架有session插件可以使用. 见如下介绍: https://www.tuto ...
- Swagger UI及 Swagger editor教程 API文档搭配 Node使用
swagger ui 是一个在线文档生成和测试的利器,目前发现最好用的.为啥好用呢?打开 demo,支持API自动生成同步的在线文档些文档可用于项目内部API审核方便测试人员了解 API这些文档可作为 ...
- 虚拟机14安装kail Linux
需要准备虚拟机和kail Linux镜像 1. 2.选择镜像安装,并且添加你的kail Linux镜像文件. 3. 4.在这里需要修改虚拟机名称,也可以不修改就用默认,然后在修改kail Linux的 ...
- 获取电脑系统唯一GUID
软件使用微软系统的唯一ID绑定指定电脑 class Program { static void Main(string[] args) { string sysId = ""; P ...
- rootkit后门检测工具
1. 关于rootkit rootkit是Linux平台下最常见的一种木马后门工具,它主要通过替换系统文件来达到入侵和和隐蔽的目的,这种木马比普通木马后门更加危险和隐蔽,普通的检测工具和检查手段很难发 ...
- 【项目】Selenium和pymongo复习
import pymongo client = pymongo.MongoClient(host='localhost',port=27017) db = client.test collection ...
- # 20175333曹雅坤《Java程序设计》第五周学习总结
教材学习内容总结 第六章要点: 1.接口:1)接口声明: interface //接口的名字 2)接口体 2.实现接口:类实现接口:一个类需要在类声明中使用关键字implements声明该类实现一个或 ...
- Access denied for user ‘root’@‘localhost’(using password: YES)的解决方法
https://www.jb51.net/article/133836.htm 搭建服务器之后只能看见test与infomation_schema两个库 https://www.cnblogs.com ...
- expect 批量自动部署ssh 免密登陆 之 二
#!/usr/bin/expect -f ########################################## hutu #Push the id.pas.pub public key ...
- ftp和mysql数据库结合使用
问题描述: 看下 1.1.1.1 的ftp为什么连不上 报错的信息: 'ftpServer' => '1.1.1.1', // FTP服务器地址 ', 'ftpUsername' => ' ...