#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. POJ 2101

    #include <iostream> #include <algorithm> #include <cmath> using namespace std; int ...

  2. Android中的Adapter总结

    一.Adapter的介绍 An Adapter object acts as a bridge between an AdapterView and the underlying data for t ...

  3. Services学习(一)

    对于需要长期运行,例如播放音乐.长期和服务器的连接,即使已不是屏幕当前的activity仍需要运行的情况,采用服务方式.服务将通过API触发启动或者通过IPC(Interprocess Communi ...

  4. hdu 3092 Least common multiple

    思路: 容易知道,分解成素数的lcm肯定是最大的,因为假设分解成2个合数,设定x为他们的 最大公约数, 那么他们的最小公倍数就要减少x倍了 然后如果是素数之间的最小公倍数,那么就只是他们的乘积,同样的 ...

  5. (6)妈的终于找到能用的nehe sdk了

    在网上下载了有十多个,终于找到一个能用的了 下面是下载地址: http://download.csdn.net/detail/jason_bourn/681620#comment 泪奔啊~

  6. hdu 3118(二进制枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3118 思路:题目要求是去掉最少的边使得图中不存在路径长度为奇数的环,这个问题等价于在图中去掉若干条边, ...

  7. JS之数组

    1.数组的定义: (1)字面量:  var arr = [1, 2, 3];  (2) new:   var arr = new Array(1, 2, 3);(using new and don't ...

  8. HBase使用场景和成功案例

    1 典型互联网搜索问题:BigTable发明的原因 搜索使用场景 1) 爬虫持续不断地抓取新页面,这些页面每页一行地存储到HBase里. 2 )MapReduce计算作业运行在整张表上,生成索引,为网 ...

  9. 安卓开发利用外部jar包时ClassNotFound的错误

    今天调试一个小程序,一直没有进入 MainActivity 中的onCreate方法,因为没有看见提前设置好的log,然后仔细观察logcat的日志,发现提示很多ClassNotFound的信息,而且 ...

  10. LR_问题_平均响应时间解释,summary与analysis不一致

    Summary Report中的时间说明 Summary是按整个场景的时间来做平均的,最大最小值,也是从整个场景中取出来的. (1)       平均响应时间:事物全部响应时间做平均计算 (2)    ...