結果

問題 No.278 連続する整数の和(2)
ユーザー uafr_cs
提出日時 2015-09-04 23:06:30
言語 Java
(openjdk 23)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 2,457 ms
コンパイル使用メモリ 75,312 KB
実行使用メモリ 41,668 KB
最終ジャッジ日時 2024-12-23 09:01:30
合計ジャッジ時間 6,363 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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 long max = N % 2 != 0 ? N : N / 2;
		//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