记录编号 |
123674 |
评测结果 |
AAAAAAAAAA |
题目名称 |
eins |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
2.320 s |
提交时间 |
2014-09-28 17:14:38 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
int Mod;
struct Martix{
LL num[3][3];
Martix(){memset(num,0,sizeof(num));}
Martix operator *(const Martix &rhs) const{
Martix res;
res.num[0][0]=(num[0][0]*rhs.num[0][0]+num[0][1]*rhs.num[1][0])%Mod;
res.num[0][1]=(num[0][0]*rhs.num[0][1]+num[0][1]*rhs.num[1][1])%Mod;
res.num[1][0]=(num[1][0]*rhs.num[0][0]+num[1][1]*rhs.num[1][0])%Mod;
res.num[1][1]=(num[1][0]*rhs.num[0][1]+num[1][1]*rhs.num[1][1])%Mod;
return res;
}
};
//==============var declaration=================
int n;
Martix One;
//==============function declaration============
Martix quickpow(int Exp);
//==============main code=======================
int main()
{
string FileName="eins";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
ios::sync_with_stdio(false);
int T;
One.num[0][0]=One.num[1][0]=One.num[0][1]=1;One.num[1][1]=0;
scanf("%d",&T);
while (T--){
scanf("%d%d",&n,&Mod);
if (n==1){
if (Mod!=1)
printf("1\n");
else
printf("0\n");
continue;
}
else if (n==0){
printf("%d\n",0);
continue;
}
n--;
Martix ans=quickpow(n);
printf("%lld\n",ans.num[0][0]);
}
#ifdef DEBUG
clock_t End_Time=clock();
cout<<endl<<endl<<"Time Used: "<<double(End_Time-Start_Time)*1000/(CLOCKS_PER_SEC)<<" Ms"<<endl;
#endif
return 0;
}
//================fuction code====================
Martix quickpow(int Exp)
{
if (Exp==1)
return One;
Martix temp=quickpow(Exp/2);
temp=temp*temp;
if (Exp&1)
temp=temp*One;
return temp;
}