結果

問題 No.152 貯金箱の消失
コンテスト
ユーザー suppy193
提出日時 2015-07-02 12:55:38
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 849 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 195 ms
コンパイル使用メモリ 40,312 KB
最終ジャッジ日時 2026-02-23 18:37:50
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <math.h>

int each_prime(long long int m, long long int n) {
	long long int r;
	long long int tmp;
	if(m < n){
		tmp = m;
		m = n;
		n = tmp;
	}
	for(;;){
		if(n == 1){
			return 1;
		}
		r = m % n;
		if(r == 0){
			return 0;
		}
		else if(r == 1){
			return 1;
		}
		m = n;
		n = r;
	}	
	//printf("%d\n", flag);
	//return flag;
}

int main(void) {
	long long int m, n, l;
	long long int a, b, c;
	long long int count;
	scanf("%lld", &l);
	count = 0;
	for(m = 2;m < sqrt(l / 4);m++){
		for(n = 1;n < m;n++){
			//printf("%d, %d\n", m, n);
			if((m - n) % 2 == 1 && each_prime(m, n) == 1){
				a = m * m - n * n;
				b = 2 * m * n;
				c = m * m + n * n;
				if((a + b + c) * 4 <= l){
					//printf("%d, %d:(%d, %d, %d)\n", m, n, a, b, c);
					count++;
				}
			}
		}
	}
	printf("%lld\n", count % 1000003);
	
	return 0;
}
0