[poj3070]Fibonacci_矩乘_快速幂】的更多相关文章

Fibonacci poj-3070 题目大意:求Fibonacci第n项. 注释:模数为10000,$1\le n \le 10^9$. 想法:矩阵题,用例题6的想法,我们构造矩阵 $\begin{pmatrix} 0 & 1 \\ 1 & 1 \end{pmatrix}$ 然后,我们快速幂即可. 附上lijinnn的版子 struct Matr { int a[4][4]; Matr(){memset(a,0,sizeof a);} Matr operator *(const Matr…
BZOJ_2242_[SDOI2011]计算器_快速幂+扩展GCD+BSGS 题意: 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给定y,z,p,计算满足Y^x ≡ Z ( mod P)的最小非负整数.   分析: 各种板子题   代码: // luogu-judger-enable-o2 // luogu-judger-enable-o2 #include <std…
超短代码 #include<iostream> #include<cstdio> using namespace std; long long b,p,k; long long Pow(long long n,long long m,long long k){//快速幂啊 if(m==1)return n%k; else {long long r=Pow(n,m>>1,k);return (r*r%k)*(m%2?(n%k):1)%k;}//表达式 } int main…
C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal…
生成树 bzoj-2467 中山市选2010 题目大意:题目链接 注释:略. 想法:首先,考虑生成树的性质.每两个点之间有且只有一条路径.我们将每个五边形的5条边分为外面的4条边和内部的一条边,在此简称为外边和内边.那么显然,每个五边形的4条外边至少需要选3条. 如果选了3条外边而且内边也没选,那么这个五边形就会被拆成两个部分.如果有2个五边形这么做,就会有两个部分之间直接断开,不符合生成树的定义.而且想让一个五边形和另一个五边形断开或者这个五边形从自身断开,只有这一种方案.如果没有任何一个五边…
Code: #include<cstdio> using namespace std; typedef long long ll; const int maxn=10000000+1; long long mod; ll fac[maxn]; ll inv[maxn]; ll anss[maxn]; int cnt,prime[maxn]; bool vis[maxn]; ll pow(ll base,ll k) { ll ans=1; while(k) { if(k&1) ans=(…
Code: #include <cstdio> #include <algorithm> #include <cstring> using namespace std; #define setIO(s) freopen(s".in","r",stdin) #define maxn 2300000 #define mod 19930726 #define ll long long char str[maxn],s[maxn]; in…
矩阵快速幂和普通的快速幂差不多,只不过写起来比较麻烦一点,需要重载*运算符. 模板: struct mat { int m[maxn][maxn]; }unit; mat operator * (mat a,mat b) { mat ret; ll x; ;i < n;i++) ;j < n;j++) { x = ; ;k < n;k++) x += mod((ll)a.m[i][k]*b.m[k][j]); ret.m[i][j] = mod(x); } return ret; } v…
又见斐波那契数列 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 斐波那契数列大家应该很熟悉了吧.下面给大家引入一种新的斐波那契数列:M斐波那契数列. M斐波那契数列F[n]是一种整数数列,它的定义如下:F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n > 1 )现在给出a, b, n,聪明的你能求出F[n]的值吗?   输入 输入包含多组测试数据:每组数据占一行,包含3个整数a, b, n( 0 <= a, b, n &l…
fibonacci数列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, - An alter…