結果

問題 No.1143 面積Nの三角形
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-07-31 22:16:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 518 ms / 800 ms
コード長 2,128 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 96,956 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 23:49:54
合計ジャッジ時間 4,496 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

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) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

int N;

int len;
int ps[110], es[110];
Int pfs[110][110];

int ans;
void dfs(int i, Int x0, Int x1, Int x2, Int x3) {
  if (i == len) {
    if (x1 >= x2 && x2 >= x3 && x0 == x1 + x2 + x3) {
      ++ans;
    }
  } else {
    for (int f0 = 0; f0 <= es[i]; ++f0) {
      for (int f1 = 0; f1 <= es[i] - f0; ++f1) {
        for (int f2 = 0; f2 <= es[i] - f0 - f1; ++f2) {
          const int f3 = es[i] - f0 - f1 - f2;
          dfs(i + 1, x0 * pfs[i][f0], x1 * pfs[i][f1], x2 * pfs[i][f2], x3 * pfs[i][f3]);
        }
      }
    }
  }
}

int main() {
  for (; ~scanf("%d", &N); ) {
    len = 0;
    int n = N;
    for (Int p = 2; p * p <= n; ++p) {
      if (n % p == 0) {
        int e = 0;
        do {
          ++e;
          n /= p;
        } while (n % p == 0);
        ps[len] = p;
        es[len] = 2 * e;
        ++len;
      }
    }
    if (n > 1) {
      ps[len] = n;
      es[len] = 2;
      ++len;
    }
// cerr<<"ps = ";pv(ps,ps+len);
// cerr<<"es = ";pv(es,es+len);
    for (int i = 0; i < len; ++i) {
      pfs[i][0] = 1;
      for (int f = 0; f < es[i]; ++f) {
        pfs[i][f + 1] = pfs[i][f] * ps[i];
      }
    }
    ans = 0;
    dfs(0, 1, 1, 1, 1);
    printf("%d\n", ans);
  }
  return 0;
}
0