【構造共軛函式+矩陣快速冪】HDU 4565 So Easy! (2013 長沙賽區邀請賽)
【題目連結】 :click here~~
【題目大意】:
A sequence Sn is defined as:

Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn.
You, a top coder, say: So easy!
【解題思路】
給一張神圖,推理寫的灰常明白了,關鍵是構造共軛函式,這一點實在是要有數學知識的理論基礎,推出了遞推式,接下來就是矩陣的快速冪了。
給個大神的連結:構造類斐波那契數列的矩陣快速冪
神圖:click here~~
程式碼:
/*
* Problem: HDU No.4565
* Running time: 62MS
* Complier: G++
* Author: javaherongwei
* Create Time: 9:55 2015/9/21 星期一
*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL siz=2; // max size of the matrix,
#define MODD(a,b) (((a%b)+b)%b)
LL A,B,N,M,ret;
struct mut
{
LL mat[siz][siz];
mut(){
memset(mat,0,sizeof(mat));
}
void init(LL a,LL b,LL c,LL d){
mat[0][0]=a;mat[0][1]=b;
mat[1][0]=c;mat[1][1]=d;
}
mut operator *(const mut &c)
{
mut res;
for(int i=0; i<siz; ++i){
for(int k=0; k<siz; ++k){
for(int j=0; j<siz; ++j){
res.mat[i][j]=MODD(res.mat[i][j]+mat[i][k]*c.mat[k][j],M);
}
}
}
return res;
}
}AC;
mut poww(LL n)
{
mut ans;
ans.init(1,0,0,1);
while(n){
if(n&1) ans=ans*AC;
n>>=1;
AC=AC*AC;
}
return ans;
}
int main()
{
while(~scanf("%lld %lld %lld %lld",&A,&B,&N,&M)){
if(N<=1){
printf("%lld\n",2*A%M);
}
else{
AC.init(2*A,B-A*A,1,0);
mut ans=poww(N-1);
printf("%lld\n",MODD(2*A%M*ans.mat[0][0]+2*ans.mat[0][1],M));
}
} return 0;
}
相關文章
- HDU 1005 Number Sequence(矩陣快速冪)矩陣
- HDU 2256Problem of Precision(矩陣快速冪)矩陣
- HDU 2157 How many ways?? (矩陣快速冪)矩陣
- HDU 2276 - Kiki & Little Kiki 2 (矩陣快速冪)矩陣
- 矩陣快速冪矩陣
- 矩陣快速冪總結矩陣
- 矩陣快速冪(快忘了)矩陣
- 矩陣快速冪加速最短路矩陣
- 矩陣快速冪最佳化矩陣
- 【矩陣乘法】【快速冪】遞推矩陣
- 演算法學習:矩陣快速冪/矩陣加速演算法矩陣
- POJ 3613 Cow Relays 矩陣乘法Floyd+矩陣快速冪矩陣
- HDU 4549 M斐波那契數列(矩陣快速冪+費馬小定理)矩陣
- 2018天梯賽、藍橋杯、(CCPC省賽、邀請賽、ICPC邀請賽)校內選拔賽反思總結!
- 2024矩陣杯初賽矩陣
- BZOJ 3329 Xorequ:數位dp + 矩陣快速冪矩陣
- 從斐波那契到矩陣快速冪矩陣
- 資訊學奧賽複賽複習16-CSP-J2022-01乘方-迴圈特判、pow函式、快速冪函式
- 2024ccpc濟南邀請賽
- 田忌賽馬博弈矩陣分析矩陣
- 這些 JavaScript函式讓你的工作更加 So Easy!JavaScript函式
- 2024 CCPC 鄭州邀請賽遊記
- ICPC2024 昆明邀請賽 遊記
- 2024CCPC山東邀請賽 IAFCK
- 第?課——基於矩陣快速冪的遞推解法矩陣
- 費馬小定理 + 費馬大定理 + 勾股數的求解 + 快速冪 + 矩陣快速冪 【模板】矩陣
- 邀請函(針對全國會長的“知博會”邀請函文案)
- bzoj4887: [Tjoi2017]可樂(矩陣乘法+快速冪)矩陣
- 觀賽邀請|春季超音速四強誕生,邀您見證決賽精彩時刻
- HDU 2197 本原串 (規律+快速冪)
- webgl內建函式--幾何函式與矩陣函式Web函式矩陣
- excel如何做共詞矩陣?excel做共詞矩陣教程Excel矩陣
- poj--2778DNA Sequence+AC自動機+矩陣快速冪矩陣
- 2013年省賽b組
- BZOJ3329: Xorequ(二進位制數位dp 矩陣快速冪)矩陣
- 2024“圖森未來杯”程式設計邀請賽程式設計
- BZOJ 3240: [Noi2013]矩陣遊戲矩陣遊戲
- 《戰爭藝術大師賽》主播邀請賽賽程過半 晉級門票花落誰家?
- POJ 3233 Matrix Power Series (矩陣快速冪+等比數列二分求和)矩陣