結果

問題 No.500 階乗電卓
ユーザー mori_chibi
提出日時 2017-08-18 16:39:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 110,848 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2024-06-25 03:03:28
合計ジャッジ時間 2,087 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.

ソースコード

diff #

using System;

namespace FactCalc
{
    class Program
    {
        static void Main(string[] args)
        {
            const long c = 1000000000000;
            long n = long.Parse(Console.ReadLine());
            bool f = false;
            if (n < 50)
            {
                for (long i = n - 1; i > 1; i--)
                {
                    if (f || n * i / c >= 1)
                    {
                        f = true;
                    }
                    n = (n * i) % c;
                }
            }
            else
            {
                n = 0;
                f = true;
            }
            string s = n.ToString("#");
            if (f)
            {
                s = s.PadLeft(12).Replace(" ", "0");
            }
            Console.WriteLine(s);
        }
    }
}
0