結果
問題 | No.747 循環小数N桁目 Hard |
ユーザー |
![]() |
提出日時 | 2019-05-06 17:06:23 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,365 bytes |
コンパイル時間 | 199 ms |
コンパイル使用メモリ | 29,824 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 23:25:59 |
合計ジャッジ時間 | 3,703 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 120 |
コンパイルメッセージ
main.c: In function 'ins': main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 7 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:16:17: note: in expansion of macro 'gc' 16 | do *s = 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:78:9: note: in expansion of macro 'pc' 78 | pc(ans[p]), pc('\n'); | ^~
ソースコード
// 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; }