結果

問題 No.1143 面積Nの三角形
コンテスト
ユーザー risujiroh
提出日時 2020-07-31 23:00:41
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 58 ms / 800 ms
コード長 1,068 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,558 ms
コンパイル使用メモリ 228,124 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-11 22:02:00
合計ジャッジ時間 3,100 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T> vector<T> divisors(T n) {
  vector<T> res;
  for (T d = 1; d * d <= n; ++d)
    if (n % d == 0) res.push_back(d), res.push_back(n / d);
  sort(begin(res), end(res));
  return {begin(res), unique(begin(res), end(res))};
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int _n;
  cin >> _n;
  using ll = __int128_t;
  ll n = (ll)_n * _n;
  auto ds = divisors(n);
  vector<tuple<ll, ll, ll>> v;
  for (ll s : ds) {
    for (ll sa : ds) {
      if (sa >= s) break;
      if (s > n / sa) break;
      ll a = s - sa;
      ll x = a * a - 4 * n / (s * sa);
      if (x < 0) continue;
      ll d = sqrt(x + 0.5);
      ll b = ((2 * s - a) - d) / 2, c = ((2 * s - a) + d) / 2;
      if (a <= b and c < a + b) {
        if (s * (s - a) * (s - b) * (s - c) == n) {
          v.emplace_back(a, b, c);
        }
      }
    }
  }
  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
  cout << size(v) << '\n';
}
0