結果

問題 No.344 ある無理数の累乗
ユーザー HachimoriHachimori
提出日時 2016-02-13 16:51:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 56,712 KB
実行使用メモリ 7,556 KB
最終ジャッジ日時 2023-10-22 04:59:02
合計ジャッジ時間 1,606 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstring>
using namespace std;
const int MOD = 1000;


int n;

void read() {
    cin >> n;
}


void work() {
    if (n == 0) {
        cout << 1 << endl;
        return;
    }
    
    if (n == 1) {
        cout << 2 << endl;
        return;
    }
    
    static int visited[MOD][MOD];
    memset(visited, -1, sizeof(visited));

    
    visited[2][2] = 0;
    int pre1 = 2;
    int pre2 = 2;
    
    for (int i = 2; i < n; ++i) {
        int cur = 2 * (pre1 + pre2) % MOD;

        if (visited[cur][pre1] >= 0) {
            int cycle = i - visited[cur][pre1];
            
            for (int j = 0; j < (n - i) % cycle; ++j) {
                cur = 2 * (pre1 + pre2) % MOD;
                pre2 = pre1;
                pre1 = cur;
            }
            break;
        }
        
        visited[cur][pre1] = i;
        pre2 = pre1;
        pre1 = cur;
    }

    int ans = 2 * (pre1 + pre2) % MOD;
    if (n % 2 == 0) {
        ans = (ans + 999) % MOD;
    }
    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}
0