結果

問題 No.278 連続する整数の和(2)
ユーザー uafr_csuafr_cs
提出日時 2015-09-04 23:03:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 2,112 ms
コンパイル使用メモリ 74,228 KB
実行使用メモリ 56,272 KB
最終ジャッジ日時 2023-08-24 22:36:17
合計ジャッジ時間 5,302 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,740 KB
testcase_01 AC 124 ms
55,888 KB
testcase_02 AC 136 ms
56,084 KB
testcase_03 AC 119 ms
55,668 KB
testcase_04 AC 120 ms
56,108 KB
testcase_05 AC 120 ms
54,424 KB
testcase_06 AC 119 ms
55,760 KB
testcase_07 AC 121 ms
55,800 KB
testcase_08 AC 136 ms
56,132 KB
testcase_09 AC 136 ms
56,012 KB
testcase_10 AC 139 ms
55,952 KB
testcase_11 AC 137 ms
56,132 KB
testcase_12 AC 119 ms
56,072 KB
testcase_13 AC 136 ms
56,272 KB
testcase_14 AC 132 ms
56,212 KB
testcase_15 AC 133 ms
55,776 KB
testcase_16 AC 131 ms
56,240 KB
testcase_17 AC 136 ms
55,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long N = sc.nextLong();
		final BigInteger N_big = BigInteger.valueOf(N);
		
		final BigInteger const_num = N_big.multiply((N_big.subtract(BigInteger.ONE))).divide(BigInteger.ONE.add(BigInteger.ONE));
		
		
		final long max = N_big.gcd(const_num).longValue();
		//System.out.println(max);
		final long sqrt = (long)(Math.floor(Math.sqrt(max)));
		
		long answer = 0;
		for(long div_fst = 1; div_fst <= sqrt; div_fst++){
			if(max % div_fst != 0) { continue; }
			
			final long div_snd = max / div_fst;
			if(div_fst > div_snd){ break; }
			//System.out.println(div_fst + " " + div_snd);
			
			answer += div_fst;
			if(div_fst < div_snd){
				answer += div_snd;
			}
		}
		
		System.out.println(answer);
		
	}

}
0