結果

問題 No.152 貯金箱の消失
ユーザー startcppstartcpp
提出日時 2015-02-16 00:23:12
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,210 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 60,404 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 01:32:10
合計ジャッジ時間 8,506 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 178 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 96 ms
4,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//同じ直角三角形を4つ作る…3辺の合計の長さがL/4以下になる直角三角形の数を数えればよい。(ただし、相似・合同なものはまとめて一つと数える)
//L <= 12000位なら、2辺の長さを決めて直角三角形が作れるかを全て判定できる。(周の長さを固定?それはいいことなし。)
//L <= 10^7は、TLEする。
#include<iostream>
#include<cmath>
using namespace std;

int L;
bool isPrime[10000001];

void SetisPrime(int N) {
	for( int i = 0; i <= N; i++ ) {
		isPrime[i] = true;
	}
	for( int i = 2; i <= N; i++ ) {
		if ( isPrime[i] ) {
			for( int j = i*2; j <= N; j += i ) {
				isPrime[j] = false;
			}
		}
	}
}
int gcd(int big, int small) {
	if ( big%small == 0 )
		return small;
	return gcd(small, big%small);
}

int main() {
	int N, x, y;
	const long double EPS = 1e-8;
	cin >> L;
	
	N = L/4;
	SetisPrime(N);
	
	int cnt = 0;
	for( x = 1; x <= N; x++ ) {
		for( y = x+1; y <= N; y++ ) {
			if ( gcd(x, y) >= 2 ) continue;
			long double z = (long long)x*(long long)x + (long long)y*(long long)y;
			z = sqrt(z);
			if (fabs(z - (int)z) <= EPS && x + y + z <= N ) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}
0