結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 9 ms
4,348 KB
testcase_04 AC 10 ms
4,348 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 11 ms
4,348 KB
testcase_07 AC 9 ms
4,348 KB
testcase_08 AC 9 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 2 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 12 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 10 ms
4,348 KB
testcase_18 AC 8 ms
4,348 KB
testcase_19 AC 7 ms
4,348 KB
testcase_20 AC 10 ms
4,348 KB
testcase_21 AC 8 ms
4,348 KB
testcase_22 AC 8 ms
4,348 KB
testcase_23 AC 1 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
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

typedef long long ll;

int main()
{
	int i, k, a;
	ll N, K, n2, b, ans;
	
	scanf("%lld%lld", &N, &K);
	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;
	}
	printf("%lld\n", ans);		
	return 0;
}
0