多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > Hdoj 1588 Gauss Fibonacci 【矩陣快速冪】

Hdoj 1588 Gauss Fibonacci 【矩陣快速冪】

來源:程序員人生   發布時間:2015-06-16 08:29:58 閱讀次數:2439次

Gauss Fibonacci

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2584 Accepted Submission(s): 1078

Problem Description
Without expecting, Angel replied quickly.She says: “I’v heard that you’r a very clever boy. So if you wanna me be your GF, you should solve the problem called GF~. ”
How good an opportunity that Gardon can not give up! The “Problem GF” told by Angel is actually “Gauss Fibonacci”.
As we know ,Gauss is the famous mathematician who worked out the sum from 1 to 100 very quickly, and Fibonacci is the crazy man who invented some numbers.

Arithmetic progression:
g(i)=k*i+b;
We assume k and b are both non-nagetive integers.

Fibonacci Numbers:
f(0)=0
f(1)=1
f(n)=f(n⑴)+f(n⑵) (n>=2)

The Gauss Fibonacci problem is described as follows:
Given k,b,n ,calculate the sum of every f(g(i)) for 0<=i

#include <cstdio> #include <iostream> #include <cstring> using namespace std; #define LL __int64 struct node{ LL num[3][3]; }; node e, a; LL n, m, k, b; node mul(node aa, node bb){ node c; for(int i = 1; i < 3; ++i){ for(int j = 1; j < 3; ++j){ c.num[i][j] = 0; for(int k = 1; k < 3; ++k){ c.num[i][j] = (c.num[i][j]+aa.num[i][k]*bb.num[k][j])%m; } } } return c; } node fa(node a, LL n){ node b = e; while(n){ if(n&1) b = mul(a, b); n >>= 1; a = mul(a, a); } return b; } node add(node aa, node bb){ node c; for(int i = 1; i < 3; ++i){ for(int j = 1; j < 3; ++j){ c.num[i][j] = (aa.num[i][j]+bb.num[i][j])%m; } } return c; } node dg(node p, LL k){ //這里很巧 if(k == 1) return p; else if(k&1) return add(dg(p, k-1), fa(p, k)); //這里就是A^(K⑴)+A^k else return mul(dg(p, k>>1), add(fa(p, k>>1), e));//這里就是 A^k+A^(k>>1); } int main(){ e.num[1][1] = e.num[2][2] = 1; e.num[1][2] = e.num[2][1] = 0; a.num[1][1] = a.num[1][2] = a.num[2][1] = 1; a.num[2][2] = 0; while(cin >> k >> b >> n >> m){ node ak = fa(a, k); node ab = fa(a, b); node ans = dg(ak, n-1); ans = add(e, ans); ans = mul(ab, ans); cout << ans.num[1][2]<< endl; } return 0; }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 成人久久久久久 | 欧美精品亚洲精品日韩专区va | 香蕉免费看一区二区三区 | 免费国产h视频在线观看 | 国产三级精品三级在线专区1 | 久久久一区二区三区不卡 | 国内精品久久久久影院不卡 | 欧美精品v日韩精品v国产精品 | 成人香蕉xxxxxxx | 精品欧美一区二区三区精品久久 | 成年视频xxxxx在线网站 | 免费观看欧美一级高清 | 久久精品全国免费观看国产 | 中文字幕精品一区二区精品 | 亚洲一级片在线播放 | 欧美日韩大尺码免费专区 | 暖暖在线精品日本中文 | 欧美一区二区三区影院 | 国产国产精品人在线观看 | 久久www免费人成精品 | 欧美人xxx| 国产激情一区二区三区成人91 | 亚洲视频在线观看网站 | www视频免费观看 | 2022国产男人亚洲欧美天堂 | 国产视频一二 | 嘿咻视频免费网站 | aa级一级天堂片免费观看 | 日韩欧美一区二区精品久久 | 激情视频网站在线观看 | 久久在线视频播放 | 亚洲日韩aⅴ在线视频 | 国产福利精品在线 | 狠狠躁夜夜躁人人躁婷婷视频 | 俺也来俺也去俺也射 | 日韩欧美亚洲另类 | 中文乱码精品一区二区三区 | 国产精品久久久久久一区二区三区 | 日本免费不卡视频一区二区三区 | 国产人成久久久精品 | 最新国产成人综合在线观看 |