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) ...
随机推荐
- scrapy中输出中文保存中文
1.json文件中文解码: #!/usr/bin/python #coding=utf-8 #author=dahu import json with open('huxiu.json','r') a ...
- tmux 安装
安装libevent wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz tar xzv ...
- Codeforces 873E Awards For Contestants ST表
原文链接https://www.cnblogs.com/zhouzhendong/p/9255885.html 题目传送门 - CF873E 题意 现在要给 $n(n\leq 3000)$ 个学生颁奖 ...
- 20165319第五周java学习笔记
教材内容总结 1.String类和StringBuffer类都覆盖了toString方法,都是返回字符串. 所以带不带toString效果是一样的. 2.instanceOf运算符可以用来判断某个对象 ...
- Number String(DP)
题目: 题意: 给你一个字符串s,s[i] = 'D'表示排列中a[i] > a[i+1],s[i] = 'I'表示排列中a[i] < a[i+1]. 比如排列 {3, 1, 2, 7, ...
- HDU 3415 Max Sum of Max-K-sub-sequence【单调队列】
<题目链接> 题目大意: 给你一段从1~N的圆形序列,要你求出这段圆形序列中长度不超过K的最大连续子序列之和是多少,并且输出这子序列的起点和终点. 解题分析: 既然是求连续子序列之和,我们 ...
- numpy学习笔记.
import numpy as np import cv2 import matplotlib.pyplot as plt 一.数组的创建 1. 创建二维数组 np.array([ [1,2,3], ...
- 002.MySQL高可用主从复制部署
一 基础环境 主机名 系统版本 MySQL版本 主机IP master CentOS 6.8 MySQL 5.6 172.24.8.10 slave01 CentOS 6.8 MySQL 5.6 17 ...
- 附006.harbor.cfg配置文件详解
一 必须参数 需要在配置文件中设置这些参数.如果用户更新它们harbor.cfg并运行install.sh脚本以重新安装Harbor,它们将生效. hostname:目标主机的主机名,用于访问UI和注 ...
- 使用pdfBox实现pdf转图片,解决中文方块乱码等问题
一.引入依赖 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>fontbox ...