結果

問題 No.500 階乗電卓
ユーザー shinwisteriashinwisteria
提出日時 2017-04-08 10:48:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 4,330 ms
コンパイル使用メモリ 73,232 KB
実行使用メモリ 56,324 KB
最終ジャッジ日時 2023-09-07 08:36:16
合計ジャッジ時間 7,397 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,324 KB
testcase_01 AC 125 ms
56,228 KB
testcase_02 AC 126 ms
55,984 KB
testcase_03 AC 125 ms
55,740 KB
testcase_04 AC 126 ms
56,148 KB
testcase_05 AC 128 ms
54,108 KB
testcase_06 AC 127 ms
55,712 KB
testcase_07 AC 125 ms
56,212 KB
testcase_08 AC 127 ms
56,056 KB
testcase_09 AC 126 ms
55,980 KB
testcase_10 AC 126 ms
56,108 KB
testcase_11 AC 127 ms
55,928 KB
testcase_12 AC 129 ms
56,008 KB
testcase_13 AC 127 ms
55,832 KB
testcase_14 AC 125 ms
56,236 KB
testcase_15 AC 125 ms
55,768 KB
testcase_16 AC 124 ms
55,756 KB
testcase_17 AC 123 ms
55,952 KB
testcase_18 AC 125 ms
55,752 KB
testcase_19 AC 126 ms
55,672 KB
testcase_20 AC 124 ms
56,164 KB
testcase_21 AC 124 ms
56,092 KB
testcase_22 AC 124 ms
55,960 KB
権限があれば一括ダウンロードができます

ソースコード

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){
				break;
			}
		}
		
		System.out.println(str);

	}

}
0