結果

問題 No.1143 面積Nの三角形
ユーザー yukudoyukudo
提出日時 2020-08-02 00:17:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 800 ms
コード長 2,365 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 179,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 21:36:35
合計ジャッジ時間 2,785 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

vector<ll> divisors(ll N) {
  vector<ll> res;
  for (ll d = 1; d * d <= N; d++) {
    if (N % d == 0) {
      res.push_back(d);
      if (d * d != N) res.push_back(N/d);
    }
  }
  sort(ALL(res));
  return res;
}

bool isSquare(ll x) {
  ll r = (ll)sqrt(x + 0.5);
  return r * r == x;
}

int main2() {
  ll N = nextLong();

  vector<ll> divs; // N^2 の約数
  {
    vector<ll> t = divisors(N);
    REP(i, t.size()) {
      for (int j = i; j < (int)t.size(); j++) {
        divs.push_back(t[i] * t[j]);
      }
    }
    sort(ALL(divs));
    divs.erase(unique(ALL(divs)), divs.end());
  }
  // pv(ALL(divs));

  set<vector<ll>> vis;
  REP(i, divs.size()) {
    for (int j = i; j < (int)divs.size(); j++) {
      ll x = divs[i];
      ll y = divs[j];
      ll a = 1;
      ll b = (x + y);
      if (N*N < (x*y)) continue;
      ll c = -N*N / (x * y);
      ll D = (b*b -4*a*c);
      if (D < 0 || !isSquare(D)) continue;
      ll rD = (ll)sqrt(D + 0.5);

      if ((-b + rD) % 2 == 0) {
        ll z = (-b + rD) / 2;
        if (z >= 0) {
          vector<ll> v({x+y, y+z, z+x});
          sort(ALL(v));
          if (v[0] + v[1] > v[2]) vis.insert(v);
        }
      }
      if ((-b - rD) % 2 == 0) {
        ll z = (-b - rD) / 2;
        if (z >= 0) {
          vector<ll> v({x+y, y+z, z+x});
          sort(ALL(v));
          if (v[0] + v[1] > v[2]) vis.insert(v);
        }
      }
    }
  }

  int ng = 0;
  for (auto v : vis) {
    ll a = v[0];
    ll b = v[1];
    ll c = v[2];
    ll S2 = (a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c);
    // cout << a << " " << b << " " << c << "    -> " << S2/16 << endl;
    if (S2/16 != N*N) ng++;
  }

  ll ans = vis.size() - ng;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
0