#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ; //如果是1005就会RE,当不确定时,最好取大点。
int A[maxn];
#define LL unsigned long long // 注意不能用long long, 因为long long
// 最大值只能取到2 ^63 - 1
LL a, b;
int n, mod, T, t; int Period()
{
A[] = , A[] = % mod; //这里的取值也是要细心的。
int i = ;
while()
{
A[i] = (A[i-]+A[i-]) % mod;
if(A[i] == A[] && (A[i-]+A[i])%mod == A[]) return i;
i ++;
}
return ;
} int Pow(int x,LL n)
{
int ans = ;
while(n)
{
if(n & ) ans *= x;
x *= x, n >>= ;
ans %= mod, x %= mod;
}
return ans;
} int main()
{
scanf("%d", &t);
while(t --)
{
//scanf("%I64d %I64d %d", &a, &b, &n); 这两种方式在UVa中交都是WA,
//scanf("%lld %lld %d", &a, &b, &n); 特别注意当不确定时,最后用cin;
cin >> a >> b >> n;
mod = n;
T = Period(); //求出周期
mod = T;
int x = Pow(a%mod, b); //x为第一个周期中对应值的下标
printf("%d\n", A[x]);
}
return ;
}

UVa11582 Colossal Fibonacci Numbers!的更多相关文章

  1. Uva11582 Colossal Fibonacci Numbers!(同余模定理+快速幂)

    https://vjudge.net/problem/UVA-11582 首先明确,斐波那契数列在模c的前提下是有循环节的.而f[i] = f[i-1]+f[i-2](i>=2)所以只要有两个连 ...

  2. UVa-11582:Colossal Fibonacci Numbers!(模算术)

    这是个开心的题目,因为既可以自己翻译,代码又好写ヾ(๑╹◡╹)ノ" The i’th Fibonacci number f(i) is recursively defined in the f ...

  3. UVa 11582 Colossal Fibonacci Numbers! 紫书

    思路是按紫书上说的来. 参考了:https://blog.csdn.net/qwsin/article/details/51834161  的代码: #include <cstdio> # ...

  4. Colossal Fibonacci Numbers! UVA 11582 寻找循环节

    /** 题目:Colossal Fibonacci Numbers! UVA 11582 链接:https://vjudge.net/problem/UVA-11582 题意:f[0] = 1, f[ ...

  5. UVA 11582 Colossal Fibonacci Numbers(数学)

    Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ...

  6. UVa #11582 Colossal Fibonacci Numbers!

    巨大的斐波那契数 The i'th Fibonacci number f (i) is recursively defined in the following way: f (0) = 0 and  ...

  7. Colossal Fibonacci Numbers(巨大的斐波那契数)UVA 11582

    评测地址:http://acm.hust.edu.cn/vjudge/problem/41990 The i'th Fibonacci number f (i) is recursively de n ...

  8. UVA 11582 Colossal Fibonacci Numbers!(循环节打表+幂取模)

    题目链接:https://cn.vjudge.net/problem/UVA-11582 /* 问题 输入a,b,n(0<a,b<2^64(a and bwill not both be ...

  9. Colossal Fibonacci Numbers! UVA - 11582(快速幂,求解)

    Problem Description The i’th Fibonacci number f(i) is recursively defined in the following way: •f(0 ...

随机推荐

  1. Nutch配置:nutch-default.xml详解

    /×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...

  2. CamShift算法

    拟采用的方法,CamShift算法,即"Continuously Apative Mean-Shift"算法,是一种运动跟踪算法.它主要通过视频图像中运动物体的颜色信息来达到跟踪的 ...

  3. Maven的配置文件pom.xml

    Maven的配置文件pom.xml 简介: 什么是POM? POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示,名称叫做pom.xml. ...

  4. C#枚举硬件设备(升级版)

    原文:C#枚举硬件设备(升级版) 先取设备类型: ; } }

  5. Cornerstone问题

    // Cornerstone锁 Cornerstone locks a working copy whenever it performs operations suchs as commits, u ...

  6. EXT实现表格斑马线

    Ext.grid.GridPanel 单双行颜色样式(斑马线)2014-04-03 11:25 1078人阅读 评论(0) 收藏 举报分类:ExtJs(36)Ext.grid.GridPanel st ...

  7. 266. Palindrome Permutation

    题目: Given a string, determine if a permutation of the string could form a palindrome. For example,&q ...

  8. 查找当前SQL Server下的Active Session正连接着哪个数据库

    今天碰到个事.原本想把数据库设为单用户模式然后把REMOVE FILE.没想到悲剧了.因为很多进程都是需要远程连接这个库,导致别的进程抢在我前面连接了这个数据库,反到我连不上了.想把数据库切回MULT ...

  9. eclipse使用replace命令替换整个project/workspace的某个字符串

    比如说为了在调试的时候方便,我的应用程序中有很多System.out.println() 调试好了,要发布了,如何把这些一次性注释掉呢?见下图

  10. Java实体书写规范

    ** * 用户角色表 */ public class BaseUserRole implements Serializable { private static final long serialVe ...