結果

問題 No.2177 Recurring ab
ユーザー そすうぽよそすうぽよ
提出日時 2023-01-06 21:48:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,378 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 198,924 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-20 14:54:41
合計ジャッジ時間 2,537 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,388 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <variant>

#define rep2(i, k, n) for (i64 i = (i64)(k); i < (i64)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) begin(x), end(x)
#ifdef ENV_LOCAL
#define dump \
  if (1) cerr
#else
#define dump \
  if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

// using namespace harudake;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 n;
  cin >> n;
  i64 ans = 0;
  rep2(p, 2, 10) {
    i64 mx = min<i64>(p, 10) - 1;
    rep(a, mx + 1) rep(b, mx + 1) {
      if (a == b) continue;
      if (p * p - n * a * p - n * b - 1 < 0) ++ans;
    }
  }
  rep(a, 10) rep(b, 10) {
    if (a == b) continue;
    i64 c1 = -n * a;
    i64 c0 = -n * b - 1;
    i64 D = c1 * c1 - 4 * c0;
    f64 rD = sqrt(D);
    i64 lo = floor((-c1 - rD) / 2.0) - 1;
    i64 hi = ceil((-c1 + rD) / 2.0) + 1;
    while (lo <= hi) {
      if (lo * lo + c1 * lo + c0 >= 0) {
        ++lo;
        continue;
      }
      if (hi * hi + c1 * hi + c0 >= 0) {
        --hi;
        continue;
      }
      break;
    }
    // dump << a << " " << b << " " << lo << " " << hi << endl;
    lo = max<i64>(lo, 10);
    ans += max<i64>(0, hi - lo + 1);
  }
  cout << ans << endl;
  return 0;
}
0