結果

問題 No.500 階乗電卓
ユーザー shinwisteriashinwisteria
提出日時 2017-04-08 10:47:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 626 bytes
コンパイル時間 3,326 ms
コンパイル使用メモリ 71,764 KB
実行使用メモリ 56,492 KB
最終ジャッジ日時 2023-09-24 23:17:12
合計ジャッジ時間 7,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 122 ms
56,004 KB
testcase_05 AC 126 ms
56,196 KB
testcase_06 AC 122 ms
56,120 KB
testcase_07 AC 123 ms
53,996 KB
testcase_08 AC 121 ms
56,168 KB
testcase_09 AC 122 ms
56,392 KB
testcase_10 AC 125 ms
56,124 KB
testcase_11 AC 125 ms
56,140 KB
testcase_12 AC 124 ms
56,196 KB
testcase_13 AC 126 ms
55,988 KB
testcase_14 AC 125 ms
56,164 KB
testcase_15 AC 120 ms
56,468 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Kaijocalc {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		long N = s.nextLong();
		long ans = 1;
		StringBuilder str = new StringBuilder();
		s.close();
		long t = (long)Math.pow(10, 12);
		for(int i = 1;i <= N;i++){
			ans *= i;
			if(ans > t){
				str.append(ans);
				str.delete(0, str.length()-12);
				ans %= t;
			}else{
				str.delete(0, str.length());
				str.append(ans);
			}
			if(ans == 0){
				str = new StringBuilder("0");
				break;
			}
		}
		
		System.out.println(str);

	}

}
0