BZOJ1409 : Password
$f[n]\bmod q=p^{Fib[n]}\bmod q=p^{Fib[n]\bmod\varphi(q)}\bmod q$
首先线性筛预处理出所有素数,然后对于每次询问,求出$\varphi(q)$,再用矩阵快速幂求出Fib[n],最后用快速幂求答案即可。
#include<cstdio>
typedef long long ll;
const int N=46341;
int T,i,j,p[N],tot,vis[N],n,q;ll a,P;
struct mat{
ll a[2][2];
inline mat(){a[0][0]=a[0][1]=a[1][0]=a[1][1]=0;}
inline mat operator*(mat b){
mat c;
for(int i=0,j,k;i<2;i++)for(j=0;j<2;j++)for(k=0;k<2;k++)(c.a[i][j]+=a[i][k]*b.a[k][j]%P)%=P;
return c;
}
}A,B,C;
inline int phi(int n){
int t=1,i;
for(i=1;p[i]*p[i]<=n&&i<=tot;i++)if(n%p[i]==0){n/=p[i],t*=p[i]-1;while(n%p[i]==0)n/=p[i],t*=p[i];}
if(n>1)t*=n-1;
return t;
}
inline int fib(int x){
P=phi(q);
for(A=B=C=mat(),A.a[0][1]=A.a[1][0]=A.a[1][1]=B.a[1][0]=C.a[0][0]=C.a[1][1]=1;x;x>>=1,A=A*A)if(x&1)C=C*A;
C=C*B;
return C.a[0][0];
}
inline int pow(ll a,int b){ll t=1;for(;b;b>>=1,a=a*a%q)if(b&1)t=t*a%q;return t;}
int main(){
for(i=2;i<N;i++){
if(!vis[i])p[++tot]=i;
for(j=1;j<=tot;j++){
if(i*p[j]>=N)break;
vis[i*p[j]]=1;
if(i%p[j]==0)break;
}
}
scanf("%d%lld",&T,&a);
while(T--){
scanf("%d%d",&n,&q);
if(q==1){puts("0");continue;}
printf("%d\n",pow(a,fib(n)));
}
return 0;
}
BZOJ1409 : Password的更多相关文章
- 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?
p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...
- your password has expired.to log in you must change it
今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...
- MySql Access denied for user 'root'@'localhost' (using password:YES) 解决方案
关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入"mysql -uroot -pmyadmin"后出现以下错 ...
- [上架] iOS "app-specific password" 上架问题
当你的 Apple ID 改用双重认证密码时,上架 iOS App 需要去建立一个专用密码来登入 Apple ID 才能上架. 如果使用 Application Loader 上传时,得到这个讯息: ...
- [LeetCode] Strong Password Checker 密码强度检查器
A password is considered strong if below conditions are all met: It has at least 6 characters and at ...
- mysql 错误 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number 解决办法
MySQL创建用户(包括密码)时,会提示ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number: 问题原因: ...
- phpmyadmin #1045 - Access denied for user 'root'@'localhost' (using password: NO)
phpmyadmin访问遇到1045问题 #1045 - Access denied for user 'root'@'localhost' (using password: NO) 解决办法 找到p ...
- 保留password模式文本框textbox内的数据不丢失。
在asp.net 2.0环境下,使用textbox,提交到服务器再传回,如果textbox是password模式的,那么textbox内的密码(星号),就没有了! protected override ...
- Windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes
Windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes http://blog.csdn.n ...
随机推荐
- zb的生日
http://acm.nyist.net/JudgeOnline/problem.php?pid=325 zb的生日 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 ...
- Decompiled .class file,bytecode version:51.0(Java 7) Source for 'Android API 23 Platform' not found
今天在Android Studio中访问Java源码的时候,代码上方出现如下提示: 而且方法体中显示介样内容: throw new RuntimeException("Stub!" ...
- 工作中常用shell之ssh登陆不用输入"yes"
ip="192.168.5.166"ssh $ip -o StrictHostKeyChecking=no //ssh登陆不用输入"yes" ...
- 【Python】python 普通继承方式和super继承方式
Python中对象方法的定义很怪异,第一个参数一般都命名为self(相当于其它语言的this),用于传递对象本身,而在调用的时候则不必显式传递,系统会自动传递.举一个很常见的例子:>>&g ...
- cURL的几个经典实例
1.cURL请求的基本步骤: (1)初始化 (2)设置选项,包括URL (3)执行并获取HTML文档内容 (4)释放cURL句柄 <?php //1.初始化 $ch = curl_init(); ...
- 六间房PK同时观看两方视频(绕过VIP限制)+直播状态批量监测
可交换两个视频位置,记住最后播放记录,游客VIP限制也能观看视频等功能. 使用方法: 1.先运行 6.cn.live.exe 分别打开两个主播房间的网页(VIP限制也能获取视频的文件名) (房间已满提 ...
- Python Elasticsearch api
描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下面介绍了利用Python API接口进行数据查询,方便 ...
- HttpHandler简介
新建的一般处理程序后缀为.ashx,一般会另外新建一个后缀为.ashx.cs的文件,其实所有的代码都写在.ashx.cs里面,只是微软帮我们做了一个傻瓜化的转换新建的一般处理程序,如:Text1,它就 ...
- MySQL主备停机步骤与注意事项
双十一马上到了,一堆的事情,今天登录mysql数据库服务器的时候突然发现服务器时间戳不对,比北京时间快了几分钟,我的天...随后检查了其他的几台数据库服务器发现同样都存在不同的偏差,最小的比北京时间快 ...
- hp unix
HP-UNIX 命令大全 #vgdisplay -v vgname #lvdisplay -v lvfullpath #pvdisplay -v pvfullpath # ioscan –fnkC d ...