結果

問題 No.276 連続する整数の和(1)
ユーザー 37zigen37zigen
提出日時 2016-05-18 19:06:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 1,000 ms
コード長 802 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 73,916 KB
実行使用メモリ 41,608 KB
最終ジャッジ日時 2024-04-15 22:56:04
合計ジャッジ時間 3,922 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
41,060 KB
testcase_01 AC 126 ms
41,284 KB
testcase_02 AC 125 ms
41,032 KB
testcase_03 AC 126 ms
41,440 KB
testcase_04 AC 127 ms
41,164 KB
testcase_05 AC 113 ms
39,884 KB
testcase_06 AC 114 ms
40,036 KB
testcase_07 AC 128 ms
41,608 KB
testcase_08 AC 130 ms
41,480 KB
testcase_09 AC 113 ms
39,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		if(n%2==0){
			System.out.println(n/2);
		}else{
			System.out.println(n);
		}
		/*
		 * 連続するN個の正整数の和を一般に割る最大値を求めよ。
		 * 
		 * 1からMまでの和は(1/2)M(M+1)
		 * 1からM+Nまでの和は(1/2)(M+N)(M+N+1)
		 * M+1からM+Nまでの和は
		 * (1/2)( (M+N)(M+N+1) - M(M+1) )
		 * =(1/2)( MN + NM + N^2 + N )
		 * =(1/2)( 2MN + N + N^2)
		 * =(1/2)N( 2M + N + 1 )
		 * i)N=2kと書けるとき
		 * =k(2M+2k+1)
		 * より、N/2で割れる。
		 * ii)N=2k-1と書けるとき
		 * =N(M+k)
		 * よりNで割れる。
		 * 
		 * 
		 */
	}
}
0