結果

問題 No.657 テトラナッチ数列 Easy
ユーザー bal4ubal4u
提出日時 2019-04-22 15:23:49
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 1,080 ms
コンパイル使用メモリ 30,336 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 07:09:38
合計ジャッジ時間 1,185 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:24: note: in expansion of macro 'gc'
   17 |         int n = 0, c = gc();
      |                        ^~
main.c: In function 'out':
main.c:10:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:27:17: note: in expansion of macro 'pc'
   27 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: No.657 テトラナッチ数列 Easy
// 2019.4.22 bal4u
// 周期性に注目。周期 4912

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

#define MOD 17
#define PERIOD 4912
int a[5000] = {0,0,0,1,1,2,4,8,15,29};

int main()
{
	int i, Q;
	for (i = 5; i < 5000; i++) {
		a[i] = (a[i-4]+a[i-3]+a[i-2]+a[i-1]) % MOD;
	}
	Q = in(); while (Q--) out(a[(in()-1) % PERIOD]);
	return 0;
}
0