Colossal Fibonacci Numbers! UVA - 11582(快速幂,求解)
Problem Description
The i’th Fibonacci number f(i) is recursively defined in the following way:
•f(0) = 0 and f(1) = 1
•f(i + 2) = f(i + 1) + f(i) for every i ≥ 0
Your task is to compute some values of this sequence
Input
Input begins with an integer t ≤ 10, 000, the number of test cases.
Each test case consists of three integers a, b, n where 0 ≤ a, b < 2 64 (a and b will not both be zero) and 1 ≤ n ≤ 1000.
Output
For each test case, output a single line containing the remainder of ƒ(ab ) upon division by n.
Sample Input
3 1 2
2 3
744073709 184467955
Sample Output
21
题目大意:
给出a,b,n,让你计算f(a^b)%n,f(n)=f(n-1)+f(n-2);
因为是%n所以余数最多n*n种,于是我们就可以用快速幂求出是在数列中是第几个数,然后代入f[]
输出就可以了~
操作代码如下:(注:n&1为真则n为奇数)
#include<iostream>
#include<cstdio>
using namespace std;
#define ll unsigned long long
const int maxx=;
int f[maxx*maxx];
int pow(ll m,ll n,int k)
{
int b=;
while(n>)
{
if(n&)
{
b=(b*m)%k;
}
n=n>>;
m=(m*m)%k;
}
return b;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll a,b;
int n,m;
scanf("%llu%llu%d",&a,&b,&n);
if(n==||a==)
printf("0\n");
else
{
f[]=;
f[]=;
m=n*n+;
int s;
for(int i=; i<=m; i++)
{
f[i]=(f[i-]+f[i-])%n;
if(f[i]==f[]&&f[i-]==f[])
{
s=i-;
break;
}
}
int k=pow(a%s,b,s);
printf("%d\n",f[k]);
}
}
return ;
}
Colossal Fibonacci Numbers! UVA - 11582(快速幂,求解)的更多相关文章
- Colossal Fibonacci Numbers! UVA 11582 寻找循环节
/** 题目:Colossal Fibonacci Numbers! UVA 11582 链接:https://vjudge.net/problem/UVA-11582 题意:f[0] = 1, f[ ...
- 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!
题意: 斐波那契数列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) ...
- HDU 3117 Fibonacci Numbers( 矩阵快速幂 + 数学推导 )
链接:传送门 题意:给一个 n ,输出 Fibonacci 数列第 n 项,如果第 n 项的位数 >= 8 位则按照 前4位 + ... + 后4位的格式输出 思路: n < 40时位数不 ...
- UVA 11582 Colossal Fibonacci Numbers(数学)
Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ...
- UVa 11582 Colossal Fibonacci Numbers! 紫书
思路是按紫书上说的来. 参考了:https://blog.csdn.net/qwsin/article/details/51834161 的代码: #include <cstdio> # ...
- UVa-11582:Colossal Fibonacci Numbers!(模算术)
这是个开心的题目,因为既可以自己翻译,代码又好写ヾ(๑╹◡╹)ノ" The i’th Fibonacci number f(i) is recursively defined in the f ...
- UVa 11582 Colossal Fibonacci Numbers! 【大数幂取模】
题目链接:Uva 11582 [vjudge] watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fil ...
- UVa 11582 - Colossal Fibonacci Numbers!(数论)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- Mongodb java.util.NoSuchElementException:null 已解决
public static String find(){ String a=""; try{ MongoCollection<Document> collection ...
- getFieldDecorator用法(二)——封装表单模块
后台管理系统经常用到表单查询,因此做了个封装 myorder.js import React from 'react'; import { Card, Button, Table, Form, Sel ...
- https://uwsgi-docs.readthedocs.io/en/latest/Async.html
Beware! Async modes will not speed up your app, they are aimed at improving concurrency. Do not expe ...
- [转]Html 页面常用单词
Html 页面常用单词 本文来自:https://gitee.com/opencc/SchoolAppDemo 第2批: JavaScript ready 准备 function 函数 disappe ...
- 免费下载 SetupVPN CRX 3.7.0 for Chrome OR QQ浏览器
免费下载 SetupVPN CRX 3.7.0 for Chrome OR QQ浏览器 Lifetime Free VPN(微劈嗯) 下载setupvpn 3.7.0的crx文件, 打开chrome的 ...
- React开发环境配置
本文以上一篇文章继续配置:npm安装及环境配置<https://www.cnblogs.com/hzb462606/p/11565275.html> 使用 create-react-app ...
- C++ ++pos vs pos++
list<char>::iterator pos; 一般使用前置式递增(preincrement),因为它比后置式递增(postincrement)效率高,因为后置式递增内部需要一个临时对 ...
- 关于对VGA、DVI、HDMI的区别
VGA接口: DVI接口: HDMI接口 可以这么理解: 1. VGA传输普通视频信号,DVI传输高清视频信号,HDMI传输高清视频信号并支持音频传输.2. HDMI的三种接口只有大小区别,功能没有任 ...
- 嵌入(embedding)层的理解
首先,我们有一个one-hot编码的概念. 假设,我们中文,一共只有10个字...只是假设啊,那么我们用0-9就可以表示完 比如,这十个字就是“我从哪里来,要到何处去” 其分别对应“0-9”,如下: ...
- opengl球形网格生成
效果如图 准备第三方库 glew.freeglut.glm 代码包括主程序源文件mainApp.cpp.顶点着色器shader.vs.片元着色器shader.fs mainApp.cpp如下 #i ...