結果

問題 No.2262 Fractions
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-04-07 22:50:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,823 ms / 2,000 ms
コード長 1,828 bytes
コンパイル時間 1,921 ms
コンパイル使用メモリ 201,324 KB
実行使用メモリ 5,552 KB
最終ジャッジ日時 2023-08-18 00:33:29
合計ジャッジ時間 54,266 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,109 ms
4,608 KB
testcase_01 AC 106 ms
4,380 KB
testcase_02 AC 115 ms
4,380 KB
testcase_03 AC 118 ms
4,376 KB
testcase_04 AC 131 ms
4,384 KB
testcase_05 AC 121 ms
4,376 KB
testcase_06 AC 141 ms
4,380 KB
testcase_07 AC 135 ms
4,380 KB
testcase_08 AC 128 ms
4,380 KB
testcase_09 AC 142 ms
4,376 KB
testcase_10 AC 141 ms
4,376 KB
testcase_11 AC 841 ms
4,380 KB
testcase_12 AC 823 ms
4,376 KB
testcase_13 AC 843 ms
4,380 KB
testcase_14 AC 849 ms
4,376 KB
testcase_15 AC 831 ms
4,380 KB
testcase_16 AC 426 ms
4,380 KB
testcase_17 AC 423 ms
4,376 KB
testcase_18 AC 416 ms
4,380 KB
testcase_19 AC 1,548 ms
4,556 KB
testcase_20 AC 1,434 ms
4,396 KB
testcase_21 AC 1,543 ms
4,684 KB
testcase_22 AC 1,419 ms
4,380 KB
testcase_23 AC 1,234 ms
4,376 KB
testcase_24 AC 1,786 ms
5,552 KB
testcase_25 AC 1,769 ms
5,480 KB
testcase_26 AC 1,737 ms
5,380 KB
testcase_27 AC 1,789 ms
5,472 KB
testcase_28 AC 1,724 ms
5,480 KB
testcase_29 AC 1,823 ms
5,380 KB
testcase_30 AC 1,780 ms
5,396 KB
testcase_31 AC 1,817 ms
5,420 KB
testcase_32 AC 1,822 ms
5,472 KB
testcase_33 AC 1,766 ms
5,472 KB
testcase_34 AC 1,764 ms
5,464 KB
testcase_35 AC 1,818 ms
5,484 KB
testcase_36 AC 1,819 ms
5,364 KB
testcase_37 AC 12 ms
5,348 KB
testcase_38 AC 13 ms
5,456 KB
testcase_39 AC 1,550 ms
4,500 KB
testcase_40 AC 1,521 ms
4,596 KB
testcase_41 AC 1,561 ms
4,552 KB
testcase_42 AC 1,525 ms
4,572 KB
testcase_43 AC 1,547 ms
4,600 KB
testcase_44 AC 1,775 ms
5,348 KB
testcase_45 AC 1,819 ms
5,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct Fast
{
  Fast()
  {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define ll long long

template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

void solve()
{
  ll n, k;
  cin >> n >> k;

  vector<ll> dp(n + 1, 0);
  ll tot = 0;
  {
    for (int i = 1; i <= n; i++)
      dp[i] = (n / i) * (n / i);
    for (ll i = n; i >= 1; i--)
      for (ll j = i * 2; j <= n; j += i)
        dp[i] -= dp[j];
    if (dp[1] < k)
    {
      cout << -1;
      return;
    }
    tot = dp[1];
  }

  bool inv = false;
  if (k * 2 > tot)
  {
    k = tot - k + 1;
    inv = true;
  }

  {
    ll l = 0, r = n * n + 10;
    while (r - l > 1)
    {
      ll x = (l + r) / 2;
      for (ll i = n; i >= 1; i--)
      {
        dp[i] = 0;
        ll m = n / i;
        for (int a = 1; a <= m; a++)
          dp[i] += min(m, a * x / (n * n));
        for (ll j = i * 2; j <= n; j += i)
          dp[i] -= dp[j];
      }
      if (dp[1] < k)
      {
        l = x;
      }
      else
      {
        r = x;
      }
    }
    for (ll a = 1; a <= n; a++)
    {
      ll x = a * l / n / n + 1;
      ll y = a * r / n / n;
      if (x == y)
      {
        if (!inv)
        {
          cout << y << "/" << a;
        }
        else
        {
          cout << a << "/" << y;
        }
        return;
      }
    }
  }
}

int main()
{
  int t;
  cin >> t;
  while (t--)
  {
    solve();
    if (t)
    {
      cout << "\n";
    }
    else
    {
      cout << endl;
    }
  }
}
0