結果

問題 No.344 ある無理数の累乗
ユーザー rickythetarickytheta
提出日時 2016-02-12 23:33:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 1,474 ms
コンパイル使用メモリ 166,772 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 03:35:34
合計ジャッジ時間 2,416 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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==0){
    cout<<1<<endl;
  }else 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