結果

問題 No.747 循環小数N桁目 Hard
ユーザー bal4ubal4u
提出日時 2019-05-06 17:06:23
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 29,320 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 07:55:09
合計ジャッジ時間 6,955 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 AC 0 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 0 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 0 ms
4,376 KB
testcase_20 AC 0 ms
4,380 KB
testcase_21 AC 0 ms
4,380 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 0 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 0 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 0 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 0 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 0 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 0 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,384 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 0 ms
4,376 KB
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 1 ms
4,380 KB
testcase_64 AC 1 ms
4,376 KB
testcase_65 AC 1 ms
4,376 KB
testcase_66 AC 1 ms
4,376 KB
testcase_67 AC 1 ms
4,380 KB
testcase_68 AC 1 ms
4,376 KB
testcase_69 AC 1 ms
4,380 KB
testcase_70 AC 1 ms
4,376 KB
testcase_71 AC 1 ms
4,376 KB
testcase_72 AC 0 ms
4,376 KB
testcase_73 AC 1 ms
4,376 KB
testcase_74 AC 1 ms
4,376 KB
testcase_75 AC 1 ms
4,380 KB
testcase_76 AC 1 ms
4,376 KB
testcase_77 AC 1 ms
4,376 KB
testcase_78 AC 1 ms
4,384 KB
testcase_79 AC 1 ms
4,380 KB
testcase_80 AC 1 ms
4,376 KB
testcase_81 AC 1 ms
4,380 KB
testcase_82 AC 0 ms
4,380 KB
testcase_83 AC 1 ms
4,380 KB
testcase_84 AC 2 ms
4,380 KB
testcase_85 AC 1 ms
4,380 KB
testcase_86 AC 1 ms
4,376 KB
testcase_87 AC 1 ms
4,384 KB
testcase_88 AC 1 ms
4,380 KB
testcase_89 AC 0 ms
4,376 KB
testcase_90 AC 1 ms
4,376 KB
testcase_91 AC 1 ms
4,376 KB
testcase_92 AC 1 ms
4,376 KB
testcase_93 AC 1 ms
4,380 KB
testcase_94 AC 1 ms
4,380 KB
testcase_95 AC 1 ms
4,380 KB
testcase_96 AC 1 ms
4,380 KB
testcase_97 AC 1 ms
4,376 KB
testcase_98 AC 2 ms
4,376 KB
testcase_99 AC 1 ms
4,376 KB
testcase_100 AC 2 ms
4,380 KB
testcase_101 AC 1 ms
4,376 KB
testcase_102 AC 1 ms
4,380 KB
testcase_103 AC 1 ms
4,380 KB
testcase_104 AC 1 ms
4,380 KB
testcase_105 AC 1 ms
4,380 KB
testcase_106 AC 1 ms
4,376 KB
testcase_107 AC 1 ms
4,376 KB
testcase_108 AC 1 ms
4,376 KB
testcase_109 AC 1 ms
4,380 KB
testcase_110 AC 1 ms
4,376 KB
testcase_111 AC 1 ms
4,380 KB
testcase_112 AC 1 ms
4,380 KB
testcase_113 AC 1 ms
4,380 KB
testcase_114 AC 1 ms
4,380 KB
testcase_115 AC 1 ms
4,376 KB
testcase_116 AC 2 ms
4,376 KB
testcase_117 AC 1 ms
4,380 KB
testcase_118 AC 1 ms
4,376 KB
testcase_119 AC 1 ms
4,376 KB
testcase_120 AC 2 ms
4,376 KB
testcase_121 AC 1 ms
4,376 KB
testcase_122 AC 1 ms
4,380 KB
testcase_123 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘ins’ 内:
main.c:7:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:16:17: 備考: in expansion of macro ‘gc’
   16 |         do *s = gc();
      |                 ^~
main.c: 関数 ‘main’ 内:
main.c:8:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:78:9: 備考: in expansion of macro ‘pc’
   78 |         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 ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

#define NN  1000000000

void mpStr2Num(int *num, int w, char *str)
{
	char *ss;
	int  *nn;
	int  k, x;

	if (*str == '0') { *num = 0; return; }
	ss = str + w;
	x = 0, k = 1, nn = num;
	do {
		x += (*--ss - '0') * k;
		k *= 10;
		if (k == NN || ss == str) *++nn = x, x = 0, k = 1;
	} while (ss != str);
	*num = nn - num;
}

// 多倍長整数 za を 整数 ab で割ったあまり  = za % zb
int mpMod(int *za, int zb)
{
	int  i = *za;
	int  *aa = za + *za;
	int  ca = 0;
	long long x;

	while (i--) {
		x = (long long)NN * ca + *aa--;
		ca = (int)(x % zb);
	}
	return ca;
}

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

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

	// Nの入力と処理
	w = ins(s);
	if (w == 1 && *s == '1') goto Done;
	mpStr2Num(base, w, s);
	N = mpMod(base, 6);
	
	// Kの入力と処理
	w = ins(s);
	if (*s == '0') goto Done;
	K = s[w-1] & 1;
	p = a[N][K];
	
Done:
	pc(ans[p]), pc('\n');
	return 0;
}
0