結果

問題 No.500 階乗電卓
ユーザー face4
提出日時 2018-05-16 22:47:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 73,312 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-28 13:21:44
合計ジャッジ時間 1,322 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
#define MOD 1000000000000

int main(){
    ll n;
    cin >> n;
    if(n >= 50) cout << "000000000000" << endl;
    else{
        ll ans = 1;
        bool overflow = false;
        for(ll i = n; i >= 2; i--){
            ans *= i;
            if(ans > MOD){
                ans %= MOD;
                overflow = true;
            }
        }

        if(overflow)    cout << setw(12) << setfill('0') << ans << endl;
        else            cout << ans << endl;
    }

    return 0;
}
0