結果
問題 | No.2262 Fractions |
ユーザー | chro_96 |
提出日時 | 2023-04-08 09:17:24 |
言語 | C (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,295 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 31,744 KB |
実行使用メモリ | 26,516 KB |
最終ジャッジ日時 | 2024-10-03 05:26:30 |
合計ジャッジ時間 | 46,704 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
ソースコード
#include <stdio.h> 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; 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; } } printf("%lld/%lld\n", ans[0], ans[1]); } t--; } return 0; }