結果

問題 No.344 ある無理数の累乗
ユーザー rickythetarickytheta
提出日時 2016-02-12 23:32:05
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,192 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 166,764 KB
実行使用メモリ 12,036 KB
最終ジャッジ日時 2023-10-22 03:35:25
合計ジャッジ時間 8,177 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

// https://oeis.org/A080041

typedef vector<vl> mat;

mat mul(const mat &a, const mat &b){
  mat ret(2,vl(2));
  REP(k,2)REP(i,2)REP(j,2)ret[i][j]+=a[i][k]*b[k][j];
  REP(i,2)REP(j,2)ret[i][j] %= 1000;
  return ret;
}

int main(){
  ll n;
  cin>>n;
  if(n==1){
    cout<<2<<endl;
  }else if(n==2){
    cout<<7<<endl;
  }else{
    mat I(2,vl(2));
    I[0][0] = I[1][1] = 1;
    mat X(2,vl(2));
    X[0][0] = X[0][1] = 2;
    X[1][0] = 1;
    mat ret = I;
    ll t = n-1;
    while(t){
      if(t&1) ret=mul(ret,X);
      X=mul(X,X);
      t>>=1;
    }
    ll a_n = (ret[0][0]*2 + ret[0][1]*2)%1000;
    if(n%2==0) --a_n;
    cout<<a_n<<endl;
  }
  return 0;
}
0