結果

問題 No.36 素数が嫌い!
ユーザー bal4ubal4u
提出日時 2019-04-08 06:46:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 957 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 29,704 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 02:50:39
合計ジャッジ時間 1,904 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 51 ms
4,376 KB
testcase_13 AC 51 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 0 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 0 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 18 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 18 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.36 素数が嫌い!
// 2019.4.7 bal4u
// 判定: Nが素数、2つの素数の積、その他

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

int tbl[21] = { 0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1 };

// return 1:素数 2:素数2つの積 3:3つ以上素数の積 0: 2つの数の積
int cntPrime(long long *x, long long *y, long long z)
{
	int i, k, n = 0;
	
	if ((z & 1) == 0) {
		do z >>= 1, n++; while ((z & 1) == 0);
		if (n >= 3) return 3;
	}
//	if (z == 1) return n;
	k = (int)sqrt((double)z);
	for (i = 3; i <= k; i += 2) {
		if (z % i == 0) {
			if (n > 0) return 3;
			*x = i, *y = z / i;
			return 0;
		}
	}
	return n + 1;
}

int main()
{
	int ans;
	long long x, y, N;

	scanf("%lld", &N);
	if (N <= 20) ans = tbl[N];
	else {
		ans = cntPrime(&x, &y, N);
		if (ans > 0) ans = (ans >= 3);
		else {
			long long a, b;
			ans = (cntPrime(&a, &b, x) != 1 || cntPrime(&a, &b, y) != 1);
		}
	}
	puts(ans ? "YES" : "NO");
	return 0;
}
0