結果

問題 No.500 階乗電卓
ユーザー nobigomunobigomu
提出日時 2018-05-15 18:46:01
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 5,396 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 21:04:48
合計ジャッジ時間 1,426 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 9 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local ffi = require 'ffi'
local M = ffi.load 'ssl'
ffi.cdef [[
typedef struct bignum_st {
	uint64_t *d;
	int top;
	int dmax;
	int neg;
	int flags;
} BN;
typedef BN * BN_ptr;
typedef const BN * BN_srcptr;
BN_ptr BN_new(void);
void BN_free(BN_ptr);
int BN_set_word(BN_ptr, uint64_t);
int BN_mul_word(BN_ptr, uint64_t);
char * BN_bn2dec(BN_srcptr);
void CRYPTO_free(void *, const char *, int);
]]

print((function (n)
	if n>=50 then return "000000000000" end
	local b=ffi.gc(M.BN_new(),M.BN_free)
	M.BN_set_word(b,1)
	for i=2,n do M.BN_mul_word(b,i+0ULL) end
	return ffi.string(ffi.gc(M.BN_bn2dec(b),function (a) M.CRYPTO_free(a,"",0) end)):sub(-12)
end)(io.stdin:read("*n")))
0