hdu 6050 funny function
来源:互联网 发布:win7摄像头软件ecap 编辑:程序博客网 时间:2024/05/01 07:22
给定N,M,求
首先昨天先写了几个,发现
…
迭加得:
这里
j+1为奇数时
则
j+1为偶数时,
n为偶数时
则
则
同理n为奇数时一样,
其中,
n偶数
n奇数
#include<cstdio> #include<cstring>#include<iostream>using namespace std;typedef long long ll;const ll P = 1000000007;const int N=2;ll n,m;struct matrix{ ll a[N][N]; int row,col; matrix():row(N),col(N){memset(a,0,sizeof(a));} matrix(int x,int y):row(x),col(y){memset(a,0,sizeof(a));} ll* operator [] (int x){return a[x];} matrix operator * (matrix x){ matrix tmp ; for (int i=0;i<=n+1;i++) for (int j=0;j<=n+1;j++){ tmp[i][j]=0; for (int k=0;k<=n+1;k++) tmp[i][j]=(tmp[i][j]+a[i][k]*x[k][j])%P; } return tmp; } matrix operator - (matrix x){ matrix tmp ; for (int i=0;i<=n+1;i++) for (int j=0;j<=n+1;j++){ tmp[i][j]=a[i][j] - x[i][j] + P; tmp[i][j]%=P; } return tmp; } void operator *= (matrix x){*this = *this * x;} matrix operator ^ (ll x){ matrix ret; for (int i=0;i<=n+1;i++)ret[i][i]=1; matrix tmp = *this; for (;x;x>>=1,tmp*=tmp){if(x&1)ret *=tmp;} return ret; }};int main(){ long long T,nn,mm; cin>>T; n=0; while(T--){ scanf("%lld%lld",&nn,&mm); matrix A,B,ans; A[0][0]=1;A[0][1]=2;A[1][0]=1;A[1][1]=0; if(nn&1){ B[0][0]=0;B[0][1]=2; B[1][0]=1;B[1][1]=-1; } else { B[0][0]=1;B[0][1]=0; B[1][0]=0;B[1][1]=1; } ans = ((A ^ nn) - B) ^ (mm-1); cout<<(ans[0][0])<<endl; } return 0;}
然后用特征值算矩阵n次方,可以求得
除三要么用逆元,要么取模的时候先对3000000021取模,最后再对1000000007取模。
于是,
#include <cstdio>#include <cstring>#include <iostream>using namespace std;typedef long long ll;const ll P = 3000000021LL;const ll MOD = 1000000007;ll pow(ll a,ll n){ if(n==0) return 1LL; ll tmp = pow(a,n/2); if(n&1) return tmp*tmp%P*a%P; return tmp*tmp%P;}int main(){ int T; ll n,m; cin>>T; while(T--){ scanf("%lld%lld",&n,&m); ll t = pow(2LL,n); t = (t - 1) % P; t = pow(t,m-1); if(n&1) t = t * 2LL + 1; else t = t * 2LL; t /= 3LL; cout<<t%MOD<<endl; } return 0;}
阅读全文
1 0
- HDU 6050 Funny Function
- hdu 6050 Funny Function
- hdu 6050 funny function
- HDU-6050 Funny Function
- HDU 6050 Funny Function
- HDU 6050 Funny Function
- HDU 6050 Funny Function
- HDU 6050 Funny Function
- hdu 6050 Funny Function
- (多校)hdu 6050 Funny Function
- 【HDU 6050 Funny Function】 + 数学
- Funny Function(HDU 6050)
- HDU 6050 Funny Function 矩阵快速幂
- HDU 6050 Funny Function(矩阵)
- hdu 6050 Funny Function (构造矩阵)
- HDU 6050 Funny Function(快速幂)
- hdu 6050 Funny Function(快速幂)
- hdu 6050Funny Function矩阵快速幂
- 引用及操作符的重载
- spring对接InfluxDB(二)--数据获取之单条查询
- ubuntu16.04部署安装
- MFC之路 串口通信篇(之三)
- 查询占用内存和swap的程序
- hdu 6050 funny function
- python学习(一)----os模块中常用方法总结
- Android安全开发之安全使用HTTPS
- Android 6.0 运行时权限处理
- csdn精品功能源码
- Ubuntu 自己定制CD
- ☞ mysql忘记密码怎么破?
- hadoop入门之wordcount学习
- 500G技术资源分享