結果

問題 No.152 貯金箱の消失
ユーザー ty70ty70
提出日時 2015-05-29 09:21:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 1,487 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 87,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 15:27:17
合計ジャッジ時間 1,917 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MOD = (int)1e6 + 3;

int main()
{
	ios_base::sync_with_stdio(0);
	ll L; cin >> L;

	int res = 0;
	for (ll n = 1LL;n < L/4LL; n++ ){
		ll s = (ll)sqrt(16LL*n*n + 8LL*L );
		ll m8 = s - 4LL*n;
		if (m8 <= 0LL ) continue;
		for (ll m = m8/8LL; m >= n; m-- ){
			ll g1 = __gcd (m*m+n*n, 2LL*m*n );
			ll g2 = __gcd (2LL*m*n, m*m - n*n );
			if (g1 != 1LL && g2 != 1LL && g1 == g2 ) continue;
			if (__gcd (m, n ) != 1LL ) continue;
//			cerr << "m: " << m << " n: " << n << endl;
//			cerr << m*m + n*n << ':' << 2*m*n << ':' << m*m - n*n << endl;
			res = (res + 1 ) % MOD;
		} // end for
	} // end for
	cout << res << endl;

	return 0;
}
0