zoukankan      html  css  js  c++  java
  • 51nod1537 分解

    http://blog.csdn.net/qingshui23/article/details/52350523 详细题解%%%%
    对矩阵乘法的不熟悉。以及不会推公式

    #include<cstdio>
    #include<cstring>
    #include<cctype>
    #include<algorithm>
    using namespace std;
    #define rep(i,s,t) for(int i=s;i<=t;i++)
    #define dwn(i,s,t) for(int i=s;i>=t;i--)
    #define clr(x,c) memset(x,c,sizeof(x))
    #define ll long long
    const ll mod=1e9+7;
    struct node{
    	ll a[3][3];
    	node(){ clr(a,0);}
    	node operator*(const node&o)const{
    	   node t;
    	   rep(i,1,2) rep(j,1,2) rep(k,1,2) t.a[i][j]=(t.a[i][j]+a[i][k]*o.a[k][j]%mod)%mod;
    	   return t;
    	}
    }a,b;
    int main(){
    	ll n;scanf("%lld",&n);ll tmp=n;
    	a.a[1][1]=a.a[2][2]=1;
    	b.a[1][1]=b.a[1][2]=b.a[2][2]=1;b.a[2][1]=2;
    	while(n){
    		if(n&1) a=a*b;
    		b=b*b;n>>=1;
    	}
    	ll ans=a.a[1][1]*a.a[1][1]+(tmp%2);ans%=mod;
    	printf("%lld
    ",ans);
    	return 0;
    }
    

      

    基准时间限制:0.5 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
     收藏
     关注
     问(1+sqrt(2)) ^n  能否分解成 sqrt(m) +sqrt(m-1)的形式 
    如果可以 输出 m%1e9+7 否则 输出no
    Input
    一行,一个数n。(n<=10^18)
    Output
    一行,如果不存在m输出no,否则输出m%1e9+7
    Input示例
    2
    Output示例
    9
  • 相关阅读:
    P2324 [SCOI2005]骑士精神
    Codeforces Round #574 (Div. 2) A~E Solution
    P4132 [BJOI2012]算不出的等式
    spring笔记(三)
    spring笔记(二)
    C3P0连接池参数解释
    spring笔记(一)
    hibernate笔记(四)
    hibernate笔记(三)
    hibernate笔记(二)
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5862734.html
Copyright © 2011-2022 走看看