結果
問題 | No.2262 Fractions |
ユーザー | chro_96 |
提出日時 | 2023-04-08 09:29:18 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1,577 ms / 2,000 ms |
コード長 | 3,212 bytes |
コンパイル時間 | 1,384 ms |
コンパイル使用メモリ | 32,104 KB |
実行使用メモリ | 32,340 KB |
最終ジャッジ日時 | 2024-11-27 02:15:20 |
合計ジャッジ時間 | 50,640 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,007 ms
31,104 KB |
testcase_01 | AC | 236 ms
31,080 KB |
testcase_02 | AC | 243 ms
31,104 KB |
testcase_03 | AC | 244 ms
31,080 KB |
testcase_04 | AC | 264 ms
30,952 KB |
testcase_05 | AC | 239 ms
31,084 KB |
testcase_06 | AC | 261 ms
31,188 KB |
testcase_07 | AC | 256 ms
31,084 KB |
testcase_08 | AC | 240 ms
31,088 KB |
testcase_09 | AC | 260 ms
31,080 KB |
testcase_10 | AC | 261 ms
31,088 KB |
testcase_11 | AC | 929 ms
31,184 KB |
testcase_12 | AC | 925 ms
31,232 KB |
testcase_13 | AC | 932 ms
31,208 KB |
testcase_14 | AC | 953 ms
31,336 KB |
testcase_15 | AC | 930 ms
31,056 KB |
testcase_16 | AC | 492 ms
31,104 KB |
testcase_17 | AC | 490 ms
31,056 KB |
testcase_18 | AC | 484 ms
31,104 KB |
testcase_19 | AC | 1,399 ms
32,104 KB |
testcase_20 | AC | 1,332 ms
31,872 KB |
testcase_21 | AC | 1,418 ms
31,708 KB |
testcase_22 | AC | 1,323 ms
31,824 KB |
testcase_23 | AC | 1,140 ms
31,312 KB |
testcase_24 | AC | 1,531 ms
32,212 KB |
testcase_25 | AC | 1,562 ms
31,360 KB |
testcase_26 | AC | 1,500 ms
31,488 KB |
testcase_27 | AC | 1,543 ms
31,696 KB |
testcase_28 | AC | 1,528 ms
31,396 KB |
testcase_29 | AC | 1,554 ms
32,336 KB |
testcase_30 | AC | 1,565 ms
32,256 KB |
testcase_31 | AC | 1,508 ms
31,200 KB |
testcase_32 | AC | 1,547 ms
31,188 KB |
testcase_33 | AC | 1,548 ms
31,200 KB |
testcase_34 | AC | 1,576 ms
32,340 KB |
testcase_35 | AC | 1,566 ms
31,692 KB |
testcase_36 | AC | 1,577 ms
31,104 KB |
testcase_37 | AC | 84 ms
30,976 KB |
testcase_38 | AC | 85 ms
30,976 KB |
testcase_39 | AC | 1,452 ms
31,840 KB |
testcase_40 | AC | 1,444 ms
31,840 KB |
testcase_41 | AC | 1,468 ms
31,712 KB |
testcase_42 | AC | 1,462 ms
31,784 KB |
testcase_43 | AC | 1,456 ms
31,708 KB |
testcase_44 | AC | 1,545 ms
32,340 KB |
testcase_45 | AC | 1,548 ms
31,312 KB |
ソースコード
#include <stdio.h> #include <stdlib.h> int cmp_fr (const void *a, const void *b) { long long *a_ = (long long *)a; long long *b_ = (long long *)b; if (a_[0]*b_[1] < a_[1]*b_[0]) { return -1; } if (a_[0]*b_[1] > a_[1]*b_[0]) { return 1; } return 0; } int main () { int t = 0; int res = 0; long long ps[300001][10] = {}; int pcnt[300001] = {}; long long fr[300000][2] = {}; for (int i = 2; i <= 300000; i++) { if (pcnt[i] <= 0) { ps[i][0] = (long long)i; pcnt[i] = 1; for (int p = 2; i*p <= 300000; p++) { ps[i*p][pcnt[i*p]] = i; pcnt[i*p]++; } } } res = scanf("%d", &t); while (t > 0) { long long n = 0LL; long long k = 0LL; long long rcnt = 1LL; res = scanf("%lld", &n); res = scanf("%lld", &k); rcnt = n*n; for (long long i = 1LL; i <= n; i += 1LL) { for (int j = 1; j < (1<<pcnt[(int)i]); j++) { int bcnt = 0; long long p = 1LL; for (int l = 0; l < pcnt[(int)i]; l++) { if ((j&(1<<l)) > 0) { p *= ps[(int)i][l]; bcnt++; } } if (bcnt%2 == 1) { rcnt -= n/p; } else { rcnt += n/p; } } } if (rcnt < k) { printf("-1\n"); } else { long long ans[2] = {}; long long l = 0LL; long long r = (1LL<<19LL); long long div = 1LL; long long lcnt = 0LL; int frcnt = 0; int ucnt = 1; while (div <= n) { long long nxt = l+r; long long cnt = 0LL; if (nxt%2LL == 1LL) { div *= 2LL; l *= 2LL; r *= 2LL; } else { nxt /= 2LL; } for (long long i = 1LL; i <= n; i += 1LL) { long long d = (nxt*i)/div; long long diff = 0LL; if (d > n) { d = n; } for (int j = 1; j < (1<<pcnt[(int)i]); j++) { int bcnt = 0; long long p = 1LL; for (int l = 0; l < pcnt[(int)i]; l++) { if ((j&(1<<l)) > 0) { p *= ps[(int)i][l]; bcnt++; } } if (bcnt%2 == 1) { diff += d/p; } else { diff -= d/p; } } cnt += d-diff; } if (cnt < k) { l = nxt; lcnt = cnt; } else { r = nxt; rcnt = cnt; } } for (long long i = 1LL; i <= n; i += 1LL) { long long d = (r*i)/div; if (d <= n && l*i < d*div) { fr[frcnt][0] = d; fr[frcnt][1] = i; frcnt++; } } qsort(fr, frcnt, sizeof(long long)*2, cmp_fr); for (int i = 1; i < frcnt; i++) { if (fr[ucnt-1][0]*fr[i][1] != fr[ucnt-1][1]*fr[i][0]) { fr[ucnt][0] = fr[i][0]; fr[ucnt][1] = fr[i][1]; ucnt++; } else if (fr[ucnt-1][0]%fr[i][0] == 0LL) { fr[ucnt-1][0] = fr[i][0]; fr[ucnt-1][1] = fr[i][1]; } } printf("%lld/%lld\n", fr[(int)(k-lcnt-1LL)][0], fr[(int)(k-lcnt-1LL)][1]); } t--; } return 0; }