結果

問題 No.502 階乗を計算するだけ
ユーザー uafr_csuafr_cs
提出日時 2017-04-08 00:07:45
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,021 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 74,428 KB
実行使用メモリ 60,404 KB
最終ジャッジ日時 2023-09-23 03:10:45
合計ジャッジ時間 9,523 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
60,100 KB
testcase_01 AC 120 ms
56,016 KB
testcase_02 AC 122 ms
55,852 KB
testcase_03 AC 119 ms
55,608 KB
testcase_04 AC 123 ms
56,068 KB
testcase_05 AC 121 ms
55,456 KB
testcase_06 AC 122 ms
56,104 KB
testcase_07 AC 122 ms
55,864 KB
testcase_08 AC 121 ms
55,860 KB
testcase_09 AC 123 ms
55,740 KB
testcase_10 AC 121 ms
55,672 KB
testcase_11 AC 122 ms
55,848 KB
testcase_12 AC 122 ms
56,392 KB
testcase_13 AC 121 ms
55,676 KB
testcase_14 AC 122 ms
55,612 KB
testcase_15 AC 122 ms
55,788 KB
testcase_16 AC 122 ms
55,888 KB
testcase_17 AC 121 ms
56,004 KB
testcase_18 AC 125 ms
56,024 KB
testcase_19 AC 123 ms
55,976 KB
testcase_20 AC 122 ms
57,856 KB
testcase_21 AC 120 ms
56,232 KB
testcase_22 AC 134 ms
55,896 KB
testcase_23 AC 130 ms
55,964 KB
testcase_24 AC 132 ms
55,760 KB
testcase_25 AC 126 ms
56,316 KB
testcase_26 AC 129 ms
56,316 KB
testcase_27 AC 129 ms
57,840 KB
testcase_28 AC 129 ms
55,956 KB
testcase_29 AC 129 ms
56,352 KB
testcase_30 AC 132 ms
55,864 KB
testcase_31 AC 129 ms
55,688 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static final long MOD = 1000000007l;
	
	public static long mod_pow(long a, long e, long m){
		long ret = 1;
		for(; e > 0; e /= 2){
			if (e % 2 != 0) ret = (ret * a) % m;
			a = (a * a) % m;
		}
		return ret;
	}
	
	public static long mod_inv(long a, long p){
		return mod_pow(a, p - 2, p);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long N = sc.nextLong();
		
		if(N >= MOD){
			System.out.println(0);
			return;
		}
		
		if(N < MOD / 2){
			long answer = 1;
			for(int i = 2; i <= N; i++){
				answer *= i;
				answer %= MOD;
			}
			
			System.out.println(answer);
		}else{
			long answer = MOD - 1;
			
			for(long i = MOD - 1; i > N; i--){
				answer *= mod_inv(i, MOD);
				answer %= MOD;
			}
			
			System.out.println(answer);
		}
		
	}
}
0