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 ...
随机推荐
- Corn 表达式
CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...
- Cube中维度排序-通过在数据仓库增加列来实现排序
数据仓库增加排序列: 维度设置: 正确结果:
- Spark Mllib里如何建立向量标签(图文详解)
不多说,直接上干货! 注意: val pos = LabeledPoint(1, vd) val neg = LabeledPoint(2, vs) 除了这两种建立向量标签.还可以从数据库中获取固定格 ...
- mysql in和exists性能比较和使用
in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询.一直以来认为exists比in效率高的说法是不准确的. 如果查询的两个表大小相当,那么用i ...
- CentOS7.2安装MySql5.7并开启远程连接授权
1.安装mysql5.7 CentOS 7之后的版本yum的默认源中使用MariaDB替代原先MySQL,因此安装方式较为以往有一些改变: 下载mysql的源 wget http://dev.mysq ...
- SpringMVC注解方式与文件上传
目录: springmvc的注解方式 文件上传(上传图片,并显示) 一.注解 在类前面加上@Controller 表示该类是一个控制器在方法handleRequest 前面加上 @RequestMap ...
- 构造方法,this,super,final,static
1构造方法 一个Person类,属性都被private了,外界无法直接访问属性,必须对外提供相应的set和get方法.但如果需要在创建对象的同时明确对象的属性值,就需要构造方法了. 1.1定义 构建创 ...
- Kendo MVVM 数据绑定(五) Events
Kendo MVVM 数据绑定(五) Events 本篇和 Kendo MVVM 数据绑定(三) Click 类似,为事件绑定的一般形式.Events 绑定支持将 ViewModel 的方法绑定到 D ...
- 一键部署LNMP堆栈Web应用基础架构
https://market.azure.cn/Vhd/Show?vhdId=9852&version=10884 产品详情 产品介绍LEMP/LNMP 是指一组通常一起使用来运行动态网站或者 ...
- 如何处理VirtualBox启动错误消息:The vboxdrv kernel module is not loaded
我在启动minikube时,遇到如下错误消息: Starting local Kubernetes v1.10.0 cluster... Starting VM... E1010 03:27:37.9 ...