結果
問題 | No.500 階乗電卓 |
ユーザー |
|
提出日時 | 2017-05-21 22:19:22 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 2,177 bytes |
コンパイル時間 | 2,723 ms |
コンパイル使用メモリ | 115,708 KB |
実行使用メモリ | 18,432 KB |
最終ジャッジ日時 | 2024-06-25 03:01:49 |
合計ジャッジ時間 | 2,679 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.IO; using System.Linq; public class Program { public static void Main() { var so = new Solver(); //var so = new Solver("input.txt", "output.txt"); so.Solve(); } } public class Solver { private readonly Reader reader; private readonly TextWriter writer; public Solver() { reader = new Reader(Console.In); writer = Console.Out; } public Solver(string input, string output) { reader = new Reader(new StreamReader(input)); writer = new StreamWriter(output); } public void Solve() { decimal mod = (decimal)Math.Pow(10, 12); decimal N = reader.RDecimal(); decimal s = 1; bool isOver = false; for (decimal i = 1; i <= N; i++) { s = s * i; if (isOver && s == 0) { break; } else if (s >= mod) { isOver = true; s = s % mod; } } if (isOver) { writer.WriteLine(s.ToString().PadLeft(12, '0')); } else { writer.WriteLine(s.ToString()); } writer.Flush(); } } public class Reader { private readonly TextReader reader; private readonly char separator = ' '; private string[] A = new string[0]; private int i; public Reader(TextReader r) { reader = r; } public string String() { return Set(); } public int Int() { return int.Parse(Set()); } public long Long() { return long.Parse(Set()); } public decimal Decimal() { return decimal.Parse(Set()); } public string RString() { return RSet(); } public int RInt() { return int.Parse(RSet()); } public long RLong() { return long.Parse(RSet()); } public decimal RDecimal() { return decimal.Parse(RSet()); } public int[] RIntArray() { Read(); return A.Select(x => int.Parse(x)).ToArray(); } private void Read() { string line = reader.ReadLine(); A = line.Split(separator); i = 0; } private string Set() { return A[i++]; } private string RSet() { Read(); return A[i++]; } }