結果

問題 No.906 Y字グラフ
ユーザー ks2mks2m
提出日時 2019-10-11 22:59:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 3,834 ms
コンパイル使用メモリ 73,216 KB
実行使用メモリ 49,948 KB
最終ジャッジ日時 2023-08-16 19:20:39
合計ジャッジ時間 5,792 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,624 KB
testcase_01 AC 42 ms
49,612 KB
testcase_02 AC 43 ms
49,928 KB
testcase_03 AC 43 ms
49,588 KB
testcase_04 AC 43 ms
49,416 KB
testcase_05 AC 43 ms
49,608 KB
testcase_06 AC 43 ms
49,832 KB
testcase_07 AC 43 ms
49,732 KB
testcase_08 AC 43 ms
49,676 KB
testcase_09 AC 43 ms
49,532 KB
testcase_10 AC 43 ms
49,672 KB
testcase_11 AC 43 ms
49,652 KB
testcase_12 AC 44 ms
49,528 KB
testcase_13 AC 43 ms
49,612 KB
testcase_14 AC 43 ms
49,836 KB
testcase_15 AC 43 ms
49,652 KB
testcase_16 AC 43 ms
49,532 KB
testcase_17 AC 43 ms
49,800 KB
testcase_18 AC 43 ms
49,404 KB
testcase_19 AC 43 ms
49,664 KB
testcase_20 AC 43 ms
49,728 KB
testcase_21 AC 43 ms
49,732 KB
testcase_22 AC 43 ms
49,628 KB
testcase_23 AC 43 ms
49,500 KB
testcase_24 AC 44 ms
49,672 KB
testcase_25 AC 42 ms
49,780 KB
testcase_26 AC 43 ms
49,924 KB
testcase_27 AC 43 ms
49,948 KB
testcase_28 AC 43 ms
49,720 KB
testcase_29 AC 43 ms
49,600 KB
testcase_30 AC 43 ms
49,700 KB
testcase_31 AC 43 ms
49,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine()) - 1;
		br.close();

		BigInteger bi1 = BigInteger.valueOf(n - 1);
		BigInteger bi2 = BigInteger.valueOf(n - 2);
		BigInteger bi3 = BigInteger.valueOf(2);
		BigInteger bi = bi1.multiply(bi2).divide(bi3);

		long ans = (n - 1) / 2;
		if (n % 3 == 0) {
			ans--;
		}
		BigInteger bi4 = BigInteger.valueOf(ans * 3);
		bi = bi.subtract(bi4);
		if (n % 3 == 0) {
			ans++;
			bi = bi.subtract(BigInteger.ONE);
		}
		ans %= 1000000007;
		bi = bi.divide(BigInteger.valueOf(6));
		bi = bi.mod(BigInteger.valueOf(1000000007));
		ans += bi.intValue();
		ans %= 1000000007;
		System.out.println(ans);
	}
}
0