結果

問題 No.278 連続する整数の和(2)
ユーザー koyumeishikoyumeishi
提出日時 2015-09-03 09:25:46
言語 Ruby
(3.3.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 409 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 11,368 KB
実行使用メモリ 15,272 KB
最終ジャッジ日時 2023-08-24 22:34:27
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,272 KB
testcase_01 AC 78 ms
15,228 KB
testcase_02 AC 183 ms
15,028 KB
testcase_03 AC 79 ms
15,028 KB
testcase_04 AC 79 ms
15,232 KB
testcase_05 AC 78 ms
15,232 KB
testcase_06 AC 80 ms
15,112 KB
testcase_07 AC 78 ms
15,196 KB
testcase_08 AC 79 ms
15,268 KB
testcase_09 AC 78 ms
15,216 KB
testcase_10 AC 81 ms
15,056 KB
testcase_11 AC 90 ms
15,040 KB
testcase_12 AC 79 ms
15,068 KB
testcase_13 AC 149 ms
15,192 KB
testcase_14 AC 85 ms
15,116 KB
testcase_15 AC 118 ms
15,180 KB
testcase_16 AC 89 ms
15,028 KB
testcase_17 AC 85 ms
15,168 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def gcd(a,b)
	if(b==0) then
		return a;
	end
	return gcd(b,a%b);
end

def s(n)
	ret = 1;
	i = 2;
	while (i*i <= n) do
		tmp = i;
		while (n%i == 0) do
			tmp *= i;
			n /= i;
		end
		ret *= (tmp-1) / (i-1);

		i += 1;
	end

	if n!=1 then
		i = n;
		tmp = i;
		while (n%i == 0) do
			tmp *= i;
			n /= i;
		end
		ret *= (tmp-1) / (i-1);
	end

	return ret;
end

n = gets.to_i;
v = gcd(n, n*(n-1)/2);
puts s(v);
0