結果

問題 No.344 ある無理数の累乗
ユーザー 👑 Nachia
提出日時 2020-09-27 17:37:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 167,848 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-30 12:48:21
合計ジャッジ時間 2,700 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const int M = 1000;

struct Number {
    int c, r3;
};

Number operator*(Number a, Number b) {
    return {
        (a.c * b.c + 3 * a.r3 * b.r3) % M,
        (a.c * b.r3 + a.r3 * b.c) % M
    };
}
Number operator^(Number a, ULL i) {
    if (i == 0) return { 1,0 };
    Number res = (a * a) ^ (i / 2);
    if (i % 2 == 1) res = res * a;
    return res;
}

int main() {
    ULL N; cin >> N;
    Number X = { 1,1 };
    X = X ^ N;
    if(N % 2 == 0) cout << ((X.c * 2 - 1) % M) << endl;
    else cout << (X.c * 2 % M) << endl;
    return 0;
}
0