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) ...
随机推荐
- URL地址编码和解码
0. 参考 [整理]关于http(GET或POST)请求中的url地址的编码(encode)和解码(decode) python3中的urlopen对于中文url是如何处理的? 中文URL的编码问题 ...
- 【AtCoder】ARC077
C - pushpush 如果是按下标说的话 如果是偶数个 那么是 \(N,N - 2,N - 4...1,3,5...N - 1\) 如果是奇数个 \(N,N - 2,N - 4...2,4,6.. ...
- Python_列表常用操作
%d 数字 %f 浮点 %s 字符串 字符串常用功能: .strip() 默认去掉字符串两边空格#或者在括号里注明去除什么 查看列表方法:dir(列表名) .append(元素): ...
- jenkins(4): jenkins 插件
1. jenkins插件下载镜像加速 jenkins插件清华大学镜像地址 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-ce ...
- Validation failed for object='employee'. Error count: 1问题解决
2018-11-13 在表单提交时有时候会提示 Validation failed for object=’user’. Error count: 1,其中user是表的名字,Error count是 ...
- ZooKeeper用途
ZooKeeper还可以用作其他用途,例如: 数据发布与订阅(配置中心) 负载均衡 命名服务(Naming Service) 分布式通知/协调 集群管理与Master选举 分布式锁 分布式队列 一些在 ...
- B2B、B2C、C2C、O2O
B2B:企业对企业 B2B (也有写成 BTB)是指企业对企业之间的营销关系,它将企业内部网,通过 B2B 网站与客户紧密结合起来,通过网络的快速反应,为客户提供更好的服务,从而促进企业的业务发展(B ...
- mybatis sql注入
这是${}与#{}的区别,#{}采用了预编译,在SQL执行前,会先将上面的SQL发送给数据库进行编译:执行时,直接使用编译好的SQL,替换占位符“?”就可以了.因为SQL注入只能对编译过程起作用,所以 ...
- VS2017动态链接库(.dll)的生成与使用
转 https://blog.csdn.net/m0_37170593/article/details/76445972 这里以VS2017为例子,讲解一下动态链接库(.dll)的生成与使用. 一.动 ...
- POJ_2376_Cleaning Shifts【贪心】【区间覆盖】
题目链接 题目大意: 有一些奶牛,每只奶牛负责一个时间段.问覆盖完全部的时间段最少需要多少只奶牛.若不能全部覆盖,输出-1. #include <cstdio>#include <a ...