結果
| 問題 |
No.152 貯金箱の消失
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2015-02-16 00:23:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,210 bytes |
| コンパイル時間 | 526 ms |
| コンパイル使用メモリ | 60,808 KB |
| 実行使用メモリ | 14,016 KB |
| 最終ジャッジ日時 | 2024-06-23 20:36:31 |
| 合計ジャッジ時間 | 7,237 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 7 |
ソースコード
//同じ直角三角形を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;
}
startcpp