結果

問題 No.689 E869120 and Constructing Array 3
ユーザー bal4ubal4u
提出日時 2019-07-12 20:42:52
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,848 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 30,748 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 18:46:16
合計ジャッジ時間 2,907 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 0 ms
4,380 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: 備考: in expansion of macro ‘gc’
   15 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:9:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:25:21: 備考: in expansion of macro ‘pc’
   25 |         while (i--) pc(b[i]);
      |                     ^~

ソースコード

diff #

// yukicoder: No.689 E869120 and Constructing Array 3
// 2019.7.12 bal4u

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

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 正整数の表示(出力)
	int i;
	char b[20];

	i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
	while (i--) pc(b[i]);
}

int prime = 24281;    //  24251 24281 24317
int sp;
int a[20], sz, sa;

void outs(int n, int v) {
	while (n--) {
		if (!sp) sp = 1; else pc(' ');
		out(v);
	}
}

#if 1
int main()
{
	int i, k, K;

	K = in();
	if (K == 0) { pc('1'), pc('\n'); return 0; }
	while (K) {
		k = (int)sqrt((double)K);
		a[sz++] = k, sa += k, K -= k*k;
	}
	out(sa << 1), pc('\n');
	k = 0; for (i = 0; i < sz; i++) {
		k += 2;
		outs(a[i], k), outs(a[i], prime-k);
	}
	pc('\n');
	return 0;
}
#else
		
#define MAX  100005
#define SQRT 316
char notPrime[MAX] = { 1,1,0,0,1 };			// zero: if prime 
void sieve()
{
	int i, j;
	for (i = 3; i <= SQRT; i += 2) {
		if (!notPrime[i]) {
			for (j = i * i; j <= MAX; j += i) notPrime[j] = 1;
		}
	}
}

int A[300];
int main()
{
	int i, j, ans, K, s;
	
	sieve();
	scanf("%d", &K);
	for (i = 0; i < K; i++) scanf("%d", A+i);
	ans = 0;
	for (i = 0; i < K; i++) for (j = i+1; j < K; j++) {
		s = A[i] + A[j];
		if ((s & 1) && notPrime[s] == 0) ans++;
	}
	printf("ans=%d\n", ans);
	return 0;
}
#endif

#if 0
int main()
{
	int i, j, k, ma, p;
	
	sieve();
	i = 3, j = 5, ma = p = 0;
	for (k = 7; k < 30000; k+=2) {
		while (notPrime[k]) k += 2;
		if (j-i > ma && k-j > ma) {
			int a = j-i;
			if (k-j < a) a = k-j;
			ma = a;
			p = j;
		}
		i = j, j = k;
	}
	printf("prime=%d, range=%d\n", p, ma);
	return 0;
}
#endif
0