結果

問題 No.864 四方演算
ユーザー bal4ubal4u
提出日時 2019-08-17 14:36:34
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 11 ms / 1,000 ms
コード長 1,163 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 32,252 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 02:49:36
合計ジャッジ時間 1,203 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 10 ms
4,348 KB
testcase_04 AC 10 ms
4,348 KB
testcase_05 AC 7 ms
4,348 KB
testcase_06 AC 10 ms
4,348 KB
testcase_07 AC 9 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 11 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 10 ms
4,348 KB
testcase_18 AC 9 ms
4,348 KB
testcase_19 AC 7 ms
4,348 KB
testcase_20 AC 10 ms
4,348 KB
testcase_21 AC 9 ms
4,348 KB
testcase_22 AC 8 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 7 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 8 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:10:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
   10 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:18:27: note: in expansion of macro 'gc'
   18 |         ll n = 0; int c = gc();
      |                           ^~
main.c: In function 'out':
main.c:11:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
   11 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:25:17: note: in expansion of macro 'pc'
   25 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: No.864 四方演算
// 2019.8.17 bal4u

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

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

ll in() {   // 非負整数の入力
	ll n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(ll n) { // 非負整数の表示(出力)
	int i; char b[50];
	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int main()
{
	int i, k, a;
	ll N, K, n2, b, ans;
	
	N = in(), K = in();
	ans = 0, n2 = N << 1;
	k = (int)sqrt((double)K);
	if (k > n2) k = n2;

	// 4 = 2*2, 9 = 3*3 のような、ふたつの約数が等しいケースへの対応
	if (K % k == 0 && K == (ll)k*k) {
		a = k; if (a > N+1) a = n2+2-a;
		ans += (ll)(a-1)*(a-1);
		k--;
	}
	
	// 逆走行し、途中の打ち切りを狙う
	for (i = k; i >= 2; i--) if (K % i == 0) {
		a = i, b = K/i;
		if (a > N+1) a = n2+2-a;
		if (b > N+1) b = n2+2-b;
		if (b > 0) ans += ((ll)(a-1)*(b-1)) << 1;
		else break;
	}
	out(ans);		
	return 0;
}
0