結果

問題 No.747 循環小数N桁目 Hard
ユーザー bal4u
提出日時 2019-05-06 17:23:45
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 28,928 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-27 23:50:34
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 120
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'inN':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: note: in expansion of macro 'gc'
   15 |         int n = 0, c = gc();
      |                        ^~
main.c: In function 'main':
main.c:8:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:47:9: note: in expansion of macro 'pc'
   47 |         pc(ans[p]), pc('\n');
      |         ^~

ソースコード

diff #

// yukicoder: No.747 循環小数N桁目 Hard
// 2019.5.6 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int inN() { // 長い数字列 % 6
	int n = 0, c = gc();
	do n = (10 * n + (c & 0xf)) % 6, c = gc(); while (c >= '0');
	return n;
}

int inK() { // 長い数字列の最後の桁
	int p, c;
	if ((p = gc()) == '0') return 0; 
	while (1) {
		c = gc();
		if (c < '0') break;
		p = c;
	}
	return p;
}

char ans[6] = "428571";
int a[6][2] = {{0,0},{1,1},{4,2},{3,3},{4,4},{1,5}};

int main()
{
	int N, K, p = 1;

	// Nの入力と処理
	N = inN();
	
	// Kの入力と処理
	K = inK();
	if (K == 0) goto Done;
	p = a[N][K & 1];
	
Done:
	pc(ans[p]), pc('\n');
	return 0;
}
0