結果

問題 No.152 貯金箱の消失
ユーザー 👑 jupirojupiro
提出日時 2020-02-08 05:11:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 708 ms / 5,000 ms
コード長 1,685 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 127,848 KB
実行使用メモリ 39,092 KB
最終ジャッジ日時 2023-10-26 00:41:52
合計ジャッジ時間 4,333 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 6 ms
4,348 KB
testcase_05 AC 7 ms
4,348 KB
testcase_06 AC 11 ms
4,528 KB
testcase_07 AC 79 ms
9,136 KB
testcase_08 AC 696 ms
38,564 KB
testcase_09 AC 708 ms
39,092 KB
testcase_10 AC 523 ms
30,908 KB
testcase_11 AC 263 ms
19,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll gcd(ll x, ll y)
{
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll L; scanf("%lld", &L);
	ll mx = L / 4;
	vector<ll> v;
	set<tuple<ll, ll, ll>> s;
	for (ll i = 1; i * i <= mx; i++) {
		for (ll j = i + 1; j * j <= mx; j += 2) {
			if (gcd(i, j) != 1) continue;
			vector<ll> a(3);
			a[0] = j * j - i * i;
			a[1] = 2 * j * i;
			a[2] = j * j + i * i;
			sort(a.begin(), a.end());
			ll sum = 0;
			sum += a[0] + a[1] + a[2];
			if (gcd(gcd(a[0], a[1]), a[2]) == 1 && s.find(make_tuple(a[0],a[1],a[2])) == s.end()) {
				v.push_back(sum);
				s.emplace(a[0], a[1], a[2]);
			}
		}
	}
	sort(v.begin(), v.end());
	ll res = 0;
	for (ll i = 0; v[i] * 4 <= L; i++) {
		res++;

	}
	cout << res << endl;
	return 0;
}
0