結果

問題 No.1143 面積Nの三角形
ユーザー cn_449cn_449
提出日時 2020-07-31 22:23:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 800 ms
コード長 2,000 bytes
コンパイル時間 1,381 ms
コンパイル使用メモリ 137,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 00:00:07
合計ジャッジ時間 2,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 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 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 19 ms
4,380 KB
testcase_10 AC 17 ms
4,376 KB
testcase_11 AC 23 ms
4,376 KB
testcase_12 AC 27 ms
4,380 KB
testcase_13 AC 30 ms
4,376 KB
testcase_14 AC 23 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 44 ms
4,380 KB
testcase_17 AC 49 ms
4,376 KB
testcase_18 AC 44 ms
4,376 KB
testcase_19 AC 43 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

ll square(ll n) {
	ll d = sqrt(n);
	for (ll i = max(d - 5, 0ll); i <= d + 5; i++) {
		if (i * i == n) return i;
	}
	return -1;
}

typedef pair<ll, P> T;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n;
	cin >> n;
	ll m = n * n;
	vector<ll> vec;
	for (ll i = 1; i <= n; i++) {
		if (m % i == 0) vec.pb(i);
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		if (m % i) continue;
		set<T> st;
		ll pro = m / i;
		for (ll x : vec) {
			if (x >= i) break;
			if (pro % x) continue;
			ll b = i - x;
			ll c = pro / x;
			ll d = b * b - 4 * c;
			ll sd = square(d);
			if (sd == -1 || ((b + sd) & 1)) continue;
			ll y = (b + sd) / 2; ll z = (b - sd) / 2;
			ll mi = min({ x,y,z });
			ll ma = max({ x,y,z });
			st.insert(T(mi, P(x + y + z - mi - ma, ma)));
		}
		ans += st.size();
	}
	cout << ans << '\n';
}
0