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

    #include<iostream> #define MAXN 105 #include"queue" #define big_num 100000000 using ...

  3. Tomcat6启用Gzip压缩功能

    配置Tomcat根目录下/conf/server.xml文件: <Connector port="8080" protocol="HTTP/1.1" co ...

  4. http://linuxme.blog.51cto.com/1850814/372960

    http://linuxme.blog.51cto.com/1850814/372960 http://os.51cto.com/art/201404/435129.htm

  5. C#程序重启自己

    Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); Application.Exit();

  6. 转:Move all SQL Server system databases at one time

    Problem One task that you may need to do as a DBA is to move the system databases from one location ...

  7. linux下python启动第三方程序,并控制关闭

    import subprocess import os import signal p = subprocess.Popen("recordmydesktop -o /home/test/t ...

  8. delphi中的Label控件背景透明

    Label1.Transparent:=true;你在它的属性窗口把它的Transparent属性改成TRUE就行了 来自为知笔记(Wiz)

  9. TForm的显示过程

    新建一个空窗体项目,然后运行,此时首先运行: procedure TApplication.Run; begin FRunning := True; try AddExitProc(DoneAppli ...

  10. 汇编语言---call和ret指令

    汇编语言--call和ret指令 call和ret指令 call和ret指令都是转移指令,它们都修改IP,或同时修改CS和IP. 它们经常被共同用来实现子程序的设计. ret和retf ret指令用栈 ...