結果

問題 No.2262 Fractions
ユーザー 👑 chro_96chro_96
提出日時 2023-04-08 09:08:56
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,097 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 08:12:39
合計ジャッジ時間 62,959 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 TLE -
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 AC 10 ms
6,940 KB
testcase_38 AC 10 ms
6,940 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 TLE -
testcase_45 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int t = 0;
  
  int res = 0;
  
  int np[300001] = {};
  int nf[300001] = {};
  int pcnt[300001] = {};
  long long fr[300000][2] = {};
  
  np[1] = 1;
  nf[1] = 1;
  for (int i = 2; i <= 300000; i++) {
    if (np[i] <= 0) {
      pcnt[i] = 1;
      for (int p = 2; i*p <= 300000; p++) {
        np[i*p] = 1;
        pcnt[i*p]++;
        if (p%i == 0) {
          nf[i*p] = 1;
        }
      }
    }
  }
  
  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) {
      if (nf[(int)i] <= 0) {
        long long tmp = n/i;
        if (pcnt[(int)i]%2 == 0) {
          rcnt += tmp*tmp;
        } else {
          rcnt -= tmp*tmp;
        }
      }
    }
    if (rcnt < k) {
      printf("-1\n");
    } else {
      long long ans = 0LL;
      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;
          if (d > n) {
            d = n;
          }
          cnt += d;
          if (nf[(int)i] <= 0) {
            long long tmp = 0LL;
            for (long long j = 1LL; i*j <= n; j += 1LL) {
              long long d = (nxt*i*j)/div;
              if (d > n) {
                d = n;
              }
              tmp += d/i;
            }
            if (pcnt[(int)i]%2 == 0) {
              cnt += tmp;
            } else {
              cnt -= tmp;
            }
          }
        }
        if (cnt < k) {
          l = nxt;
          lcnt = cnt;
        } else {
          r = nxt;
          rcnt = cnt;
        }
      }
      printf("%lld\n", ans);
    }
    t--;
  }
  
  return 0;
}
0