結果

問題 No.657 テトラナッチ数列 Easy
ユーザー snow4726snow4726
提出日時 2018-03-18 07:19:14
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,052 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 28,852 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2023-08-26 19:33:48
合計ジャッジ時間 1,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 8 ms
9,000 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 8 ms
9,712 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 12 ms
9,728 KB
testcase_14 AC 11 ms
9,708 KB
testcase_15 AC 11 ms
9,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**********************************************************
テトラナッチ数列のni番目の項Tniを17で
割った余りを求めるプログラム
入力:niの総数、テトラナッチ数列のni番目のni
出力:テトラナッチ数列のni番目の項Tniを17で割った余りをniの総数分
**********************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>

int main(){

    long long int* data;    /* テトラナッチ数列のni番目のniをniの総数分だけ格納するポインタ */
    long long int* tetora;  /* テトラナッチ数列 */
    long long int i;    /* カウンタ */
    long long int n;    /* niの総数 */
    long long int max = -1; /* ポインタdataの中の最大値 */

    scanf("%"SCNd64"",&n); /* niの入力 */
    data = (long long int*)calloc((int)n,sizeof(long long int)); /* niの総数分領域確保 */

    /* ポインタdataに入力niを全て格納 */
    for(i=0; i<n; i++){
            scanf("%"SCNd64"",data+i);
            if( max < data[i] ) max = data[i];  /* 入力niの内、最大値を格納 */
    }

    tetora = (long long int*)calloc((int)max,sizeof(long long int)); /* 指定されたniの内、最大値分だけ領域確保 */

    /* テトラナッチ数列を求める */
    for(i=1; i<=max; i++){
        switch(i){  /* {Tn}を求めていく */
            case 1:
                tetora[i-1] = 0;    /* T1=0 */
                break;
            case 2:
                tetora[i-1] = 0;    /* T2=0 */
                break;
            case 3:
                tetora[i-1] = 0;    /* T3=0 */
                break;
            case 4:
                tetora[i-1] = 1;    /* T4=1 */
                break;
            default:
                tetora[i-1] = (tetora[i-2] + tetora[i-3] + tetora[i-4] + tetora[i-5])%17;   /* Tk = Tk−1 + Tk−2 + Tk−3 + Tk−4 */
                break;
        }
    }

    for(i=0; i<n; i++){
        printf("%lld\n",tetora[data[i]-1]); /* 出力 */
    }

    return 0;
}
0