UVa11582 Colossal Fibonacci Numbers!
#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!的更多相关文章
- Uva11582 Colossal Fibonacci Numbers!(同余模定理+快速幂)
https://vjudge.net/problem/UVA-11582 首先明确,斐波那契数列在模c的前提下是有循环节的.而f[i] = f[i-1]+f[i-2](i>=2)所以只要有两个连 ...
- UVa-11582:Colossal Fibonacci Numbers!(模算术)
这是个开心的题目,因为既可以自己翻译,代码又好写ヾ(๑╹◡╹)ノ" The i’th Fibonacci number f(i) is recursively defined in the f ...
- UVa 11582 Colossal Fibonacci Numbers! 紫书
思路是按紫书上说的来. 参考了:https://blog.csdn.net/qwsin/article/details/51834161 的代码: #include <cstdio> # ...
- Colossal Fibonacci Numbers! UVA 11582 寻找循环节
/** 题目:Colossal Fibonacci Numbers! UVA 11582 链接:https://vjudge.net/problem/UVA-11582 题意:f[0] = 1, f[ ...
- UVA 11582 Colossal Fibonacci Numbers(数学)
Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ...
- UVa #11582 Colossal Fibonacci Numbers!
巨大的斐波那契数 The i'th Fibonacci number f (i) is recursively defined in the following way: f (0) = 0 and ...
- Colossal Fibonacci Numbers(巨大的斐波那契数)UVA 11582
评测地址:http://acm.hust.edu.cn/vjudge/problem/41990 The i'th Fibonacci number f (i) is recursively de n ...
- 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 ...
- Colossal Fibonacci Numbers! UVA - 11582(快速幂,求解)
Problem Description The i’th Fibonacci number f(i) is recursively defined in the following way: •f(0 ...
随机推荐
- POJ 2000
#include<iostream> #include<cstdio> #define MAXN 10009 using namespace std; ]; int main( ...
- 关于Try/Catch 代码块
应当放在Try/Catch 代码块中的常见任务包括连接到一个数据库或与其交互.处理文件.调用Web 服务. 老实说,我这人很少有打破沙锅问到底的精神.不过昨晚听一技术人员跟他的项目经理说要在程序中使用 ...
- Tomcat SSL 设置
1. 先用如下命令生成tomcat 证书 cls rem please set the env JAVA_HOME before run this bat file SET JAVA_HOME=C:\ ...
- C# 使用WIN32API设置外部程序窗口无边框
使用代码 var wnd = win32.FindWindowA(null, "窗口标题"); Int32 wndStyle = win32.GetWindowLong(wnd, ...
- hdu 1567 2006 (题意理解容易出错)
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; struct ...
- Fragment 的用法小技巧
public static class ArrayListFragment extends ListFragment { int mNum; /** * Create a new instance o ...
- HtmlAgilityPackage XPath学习
最近的开发中要用到htmlAgilityPackage, 所以记录一下XPath相关知识! XPath 简介 XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对 ...
- iOS CoreAnimation剖析
零.前言 这里没有太多的代码细节,只是探索iOS动画的基本概念,以及其抽象模型,数学基础等.我们学习一个知识的时候一般有两个部分,抽象部分和形象部分,抽象好比语言的语法,是规则,形象好比具体的句子,可 ...
- iOS sqlite3数据库解析
看来从版本3.3.1基本上已经支持线程句柄的传递功能.具体限制我标记了一下.(6) Is SQLite threadsafe?SQLite is threadsafe. We make this co ...
- spry菜单栏(一)
spry菜单栏使用教程 关于 Spry 框架 Spry 框架是一个 JavaScript 库,Web 设计人员使用它可以构建能够向站点访问者提供更丰富体验的 Web 页.有了 Spry,就可以使用 H ...