Uva11582 Colossal Fibonacci Numbers!(同余模定理+快速幂)
https://vjudge.net/problem/UVA-11582
首先明确,斐波那契数列在模c的前提下是有循环节的。而f[i] = f[i-1]+f[i-2](i>=2)所以只要有两个连续的值和开头的一样,后面就开始循环,两两组合共有c*c种。
找到循环节之后
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<set>
#include<iterator>
#include<queue>
#include<cctype>
#include<map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f
#define MAXN 100010
const int MOD=1e9;
typedef unsigned long long ll;
using namespace std;
ll t, a, b, c, M;
ll f[];
ll mod_pow(ll a, ll b, ll c)
{
ll r = a, ans=;
while(b){
if(b&){
ans = (ans*r)%c;
}
r = (r*r)%c;
b >>= ;
}
return ans;
}
int main()
{
cin >> t;
while(t--){
M=;
cin >> a >> b >> c;
f[] = ; f[] = ;
if(c==){//c=1的话进不了下面的循环,特判
cout << "" << endl;
}
else{
for(int i = ; i <= c*c; i++){//模c,余数有c种可能,两两组合有c*c种
f[i] = (f[i-]%c+f[i-]%c)%c;
if(f[i-]==f[]&&f[i]==f[]){//找到循环节
M = i-;//循环个数
break;//实际比预想的小很多,break跳出循环
}
}
cout << f[mod_pow(a%M, b, M)] << endl;//a是index
}
}
return ;
}
Uva11582 Colossal Fibonacci Numbers!(同余模定理+快速幂)的更多相关文章
- HDU 3117 Fibonacci Numbers( 矩阵快速幂 + 数学推导 )
链接:传送门 题意:给一个 n ,输出 Fibonacci 数列第 n 项,如果第 n 项的位数 >= 8 位则按照 前4位 + ... + 后4位的格式输出 思路: n < 40时位数不 ...
- UVa11582 Colossal Fibonacci Numbers!
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> us ...
- 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> # ...
- UVA 11582 Colossal Fibonacci Numbers(数学)
Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ...
- Colossal Fibonacci Numbers! UVA 11582 寻找循环节
/** 题目:Colossal Fibonacci Numbers! UVA 11582 链接:https://vjudge.net/problem/UVA-11582 题意:f[0] = 1, f[ ...
- 组合数(Lucas定理) + 快速幂 --- HDU 5226 Tom and matrix
Tom and matrix Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5226 Mean: 题意很简单,略. analy ...
- Colossal Fibonacci Numbers! UVA - 11582(快速幂,求解)
Problem Description The i’th Fibonacci number f(i) is recursively defined in the following way: •f(0 ...
- UVa 11582 (快速幂取模) Colossal Fibonacci Numbers!
题意: 斐波那契数列f(0) = 0, f(1) = 1, f(n+2) = f(n+1) + f(n) (n ≥ 0) 输入a.b.n,求f(ab)%n 分析: 构造一个新数列F(i) = f(i) ...
随机推荐
- 安装CentOS 7(转)
转载地址:https://www.cnblogs.com/wcwen1990/p/7630545.html CentOS7安装详解 本文基于vmware workstations进行CentOS7 ...
- element-ui MessageBox的bug
通过 use引用messageBox有bug Vue.use(MessageBox) 页面一开始会有一个弹窗,内容空白 Vue.component(MessageBox.name, MessageBo ...
- Genius ACM
题解: 发现匹配一定会选最大和最小匹配,确定左右端点之后nlogn排序后算 比较容易想到二分 最坏情况每次1个 $n^2*(logn)^2$ 没错暴力的最差复杂度是$n^2*logn$的 发现长度与次 ...
- Google搜索
https://www.google.com/intl/br/insidesearch/tipstricks/all.html 如何用好谷歌等搜索引擎?
- NEST 中的距离单位
Distance units Version: 5.x 英文原文地址:Distance units 当我们需要指定距离时(地理位置查询),可以使用一个双精度的数字来表示,它的默认单位是米(meters ...
- 【Android】ContentValues的用法
ContentValues 和HashTable类似都是一种存储的机制 但是两者最大的区别就在于,contenvalues只能存储基本类型的数据,像string,int之类的,不能存储对象这种东西,而 ...
- Python_datetime模块
datetime模块重新封装了time模块,提供更多的接口,提供的类有: date,表示日期的类 time,表示时间的类 datetime,表示日期和时间的类 timedelta,表示时间间隔,即两个 ...
- Python_自定义模块
自定义模块例子(web简单框架): 专门处理逻辑的包:处理各种访问需求 数据库的交互:面临各种的查询,删改 ,dba, 配置文件(全局配置文件):列存储数据的地方,HTML代码存储地方 实现: 代码: ...
- mysql-数据库管理安装
第一节 数据库管理系统 相关网址:www.db-engines.com mysql站点:www.mysql.com mariadb.org mariadb官方站点 数据库分类: 关系型数据库: o ...
- BZOJ3262/洛谷P3810 陌上花开 分治 三维偏序 树状数组
原文链接http://www.cnblogs.com/zhouzhendong/p/8672131.html 题目传送门 - BZOJ3262 题目传送门 - 洛谷P3810 题意 有$n$个元素,第 ...