結果

問題 No.523 LED
ユーザー ぴろずぴろず
提出日時 2017-06-02 22:46:42
言語 Java
(openjdk 23)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 77,200 KB
実行使用メモリ 41,768 KB
最終ジャッジ日時 2024-09-21 23:38:19
合計ジャッジ時間 8,317 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

package no523;

import java.util.Scanner;

public class Main {
	public static long MOD = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long fact = 1;
		for(int i=1;i<=2*n;i++) {
			fact = fact * i % MOD;
		}
		long ans = fact * pow(inverse(2, MOD), n, MOD) % MOD;
		System.out.println(ans);
	}
	public static long pow(long a,long n,long mod) {
		long res = 1;
		while(n > 0) {
			if ((n & 1) > 0) {
				res = (res * a) % mod;
			}
			a = (a * a) % mod;
			n/=2;
		}
		return res;
	}
	public static long inverse(long a,long mod) {
		long b = mod, u = 1, v = 0;
		while(b > 0) {
			long temp;
			long t = a / b;
			a -= t * b;
			temp = a; a = b; b = temp;
			u -= t * v;
			temp = u; u = v; v = temp;
		}
		return (u % mod + mod) % mod;
	}
}
0