日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

So Easy!(HDU - 4565)

發布時間:2025/3/17 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 So Easy!(HDU - 4565) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

A sequence S n 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 S n.?
You, a top coder, say: So easy!?

Input

There are several test cases, each test case in one line contains four positive integers: a, b, n, m. Where 0< a, m < 2 15, (a-1) 2< b < a 2, 0 < b, n < 2 31.The input will finish with the end of file.

Output

For each the case, output an integer S n.

Sample Input

2 3 1 2013
2 3 2 2013
2 2 1 2013

Sample Output

4
14
4

題意:給出 a、b、n、m 按照上圖的公式,求 Sn

思路:共軛矩陣的構造,具體思路:點擊這里

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define PI acos(-1.0) #define E 1e-9 #define INF 0x3f3f3f3f #define LL long long const int MOD=1e9+7; const int N=10+5; const int dx[]= {-1,1,0,0}; const int dy[]= {0,0,-1,1}; using namespace std; struct Matrix{LL s[N][N]; }; Matrix e;//單位矩陣E Matrix x;//構造矩陣LL mod;void init(){for(int i=1;i<=2;i++)//主對角線為1e.s[i][i]=1; } Matrix mul(Matrix A,Matrix B,LL n){//矩陣乘法,n代表A、B兩個矩陣是n階方陣Matrix temp;//臨時矩陣,存放A*B結果for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)temp.s[i][j]=0;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)temp.s[i][j]=(temp.s[i][j]+A.s[i][k]*B.s[k][j])%mod;return temp; } Matrix quickPower(Matrix a,LL b,LL n){//矩陣快速冪,求矩陣n階矩陣的b次冪Matrix ans=e;while(b){if(b&1)ans=mul(ans,a,n);//ans=e*aa=mul(a,a,n);//a=a*ab>>=1;}return ans; } int main(){init();LL a,b,n;while(scanf("%lld%lld%lld%lld",&a,&b,&n,&mod)!=EOF){if(n<=1)printf("%lld\n",((2*a)%mod+mod)%mod);else{x.s[1][1]=2*a;x.s[1][2]=-(a*a-b);x.s[2][1]=1;x.s[2][2]=0;Matrix res=quickPower(x,n-1,2);printf("%lld\n",((res.s[1][1]*2*a+res.s[1][2]*2)%mod+mod)%mod);}}return 0; }

?

總結

以上是生活随笔為你收集整理的So Easy!(HDU - 4565)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。