您的位置:首页 > 其它

UVA 11582 - Colossal Fibonacci Numbers!

2015-08-20 15:56 267 查看
不知道怎么搞的  题目粘不上来了

直接上代码吧

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
int f[10010],n,mod;
int gao()
{
f[0]=0,f[1]=1%n;
for(int i=2;;i++)
{
f[i]=(f[i-1]+f[i-2])%n;
if(f[i]==f[0]&&(f[i]+f[i-1])%n==f[1]) return i;
}
// return 1;
}
unsigned long long a,b;
int pow(int x,unsigned long long n)
{
if(n==0) return 1%mod;
int ret=pow(x,n/2);
ret=ret*ret%mod;
if(n&1)
return ret*x%mod;
else
return ret;
}
int t,T;
int main()
{
scanf("%d",&t);
while(t--)
{
cin>>a>>b>>n;
mod=gao();
int x=pow(a%mod,b);
printf("%d\n",f[x%mod]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: