ACM-ICPC 2015 Shenyang Preliminary Contest B. Best Solver
The so-called best problem solver can easily solve this problem, with his/her childhood sweetheart.
It is known that y=(5+2 *sqrt(6))^(1+2^x)
For a given integer x(0≤x<2^32) and a given prime number M(M≤46337), print [y]%M. ([y]means the integer part of y)
Input Format
An integer T(1<T≤1000), indicating there are T test cases.
Following are T lines, each containing two integers x and M, as introduced above.
Output Format
The output contains exactly T lines.
Each line contains an integer representing [y]%M.
样例输入
7
0 46337
1 46337
3 46337
1 46337
21 46337
321 46337
4321 46337
样例输出
Case #1: 97
Case #2: 969
Case #3: 16537
Case #4: 969
Case #5: 40453
Case #6: 10211
Case #7: 17947
题目来源
ACM-ICPC 2015 Shenyang Preliminary Contest
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 100005//一开始是10005,一直超时/
#define mod 1000000007
#define gep(i,a,b) for(int i=a;i<=b;i++)
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
/*
a(n)=(5+sqrt(6))^n,b(n)=(5-sqrt(6))^n
c(n)=a(n)+b(n)//是个整数
a(n)-(1-b(n))=a(n)+b(n)-1=c(n)-1为a(n)向下取整的结果。
c(n)*((5+sqrt(6))+(5-qrt(6)))
因此10*c(n)=c(n+1)+c(n-1)
c(n+1)=10*c(n)-c(n-1)
*/
int t;
ll x,m;
ll c[N];
ll len;
ll solve(){
c[]=%m;
c[]=%m;
//cout<<m<<endl;
for(int i=;;i++)
{
c[i]=(*c[i-]-c[i-]+m)%m;
//cout<<c[i]<<endl;
if(c[i-]==c[]&&c[i]==c[]){
//cout<<len<<endl;
return len=i-;
}
}
}
ll poww(ll a,ll b,ll p){
ll ans=%p;
a%=p;
while(b){
if(b&) ans=(ans*a)%p;
b>>=;
a=(a*a)%p;
}
return ans%p;
}
int main()
{
scanf("%d",&t);
gep(i,,t){
scanf("%lld%lld",&x,&m);//1+2^x(x很大)一定有循环节。
//cout<<x<<" "<<m<<endl;
solve();//因为%m的m不大,因此每次都去找循环节。
ll id=poww(,x,len);
id=(id+)%len;
printf("Case #%d: %lld\n",i,((c[id]-)%m+m)%m);
}
return ;
}
ACM-ICPC 2015 Shenyang Preliminary Contest B. Best Solver的更多相关文章
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering
Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time
Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 I. Illegal or Not?
I. Illegal or Not? time limit per test 1 second memory limit per test 512 megabytes input standard i ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 K. King’s Rout
K. King's Rout time limit per test 4 seconds memory limit per test 512 megabytes input standard inpu ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 H. Hashing
H. Hashing time limit per test 1 second memory limit per test 512 megabytes input standard input out ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 C. Colder-Hotter
C. Colder-Hotter time limit per test 1 second memory limit per test 512 megabytes input standard inp ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 A. Anagrams
A. Anagrams time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- Samara SAU ACM ICPC 2013-2014 Quarterfinal Qualification Contest
A: 简单题,因为题目中说了不会有数据相同: #include<cstdio> #include<algorithm> #define maxn 200005 using na ...
随机推荐
- (转)生产环境常见的HTTP状态码列表(老男孩整理)
生产环境常见的HTTP状态码列表(老男孩整理) 原文:http://blog.51cto.com/oldboy/716294 ##################################### ...
- (转)Linux下select, poll和epoll IO模型的详解
Linux下select, poll和epoll IO模型的详解 原文:http://blog.csdn.net/tianmohust/article/details/6677985 一).Epoll ...
- Sqoop基础学习(1)
1. Sqoop的导入过程 在开始导入之前,Sqoop会通过JDBC来获得所需要的数据库元数据 1.导入表的列名.数据类型等: 2.接着这些数据库的数据类型(varchar.number等)会把映射成 ...
- 评价PE基金绩效的常用指标
作为信息系统,辅助管理层决策是重要的功能之一.前文介绍了PE基金管理系统的建设,对PE业务的运转有了一些了解,但没有介绍如何评价PE基金的绩效,而这是管理层作出重大决策的主要依据之一.PE基金本质也是 ...
- wireshark使用教程及TCP三次握手实例
安装后,选择对应访问网络的网卡,即可看到下面的主界面 具体说下封包详细信息 (Packet Details Pane) 这个面板是我们最重要的,用来查看协议中的每一个字段. 各行信息分别为 Frame ...
- cmd_ping命令
ping命令是网络命令里的核心命令,同时也是黑客入侵的基础命令.下面和大家分享一下ping命令的基础知识和一般用法. 以ping百度公司域名为例,介绍ping命令相关内容. 一.ping命令基础知识 ...
- [windows]窗口文件夹中使用常见任务
文件夹中使用常见任务,如截图所示增加红色框部分. 设置步骤: 我的电脑--〉右键--〉属性--〉高级选项--〉性能设置--〉自定义:勾选在文件夹中使用常见任务.
- 洛谷 P2966 [USACO09DEC]牛收费路径Cow Toll Paths
题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has ...
- Android(java)学习笔记109:Java中输入和输出流概念
程序在内存中运行,文件在磁盘上,把文件从磁盘上读入内存中来,当然是输入流了, 反之,把内存中的数据写到磁盘上的文件里面去就是输出.通常都是这样的,用了过滤流的情况复杂一些,则另当别论.
- 241个jquery插件—jquery插件大全
jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多javascript高手加入其team. jQuery是继prototype之后又一个优秀的Javascrīpt框架.其经典 ...