結果

問題 No.500 階乗電卓
ユーザー nobigomunobigomu
提出日時 2018-05-14 19:36:03
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 35 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 20:43:00
合計ジャッジ時間 1,417 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

print((function (f, g, n)
	if n>=50 then return "000000000000" end
	if n<15 then return g(n) end
	return f(math.floor, g, n)
end)(function (f, g, n)
	local a,b,c,l,r,s={},{},{},1,5,tostring(g(15))
	for i=1,12 do a[i]=tonumber(s:sub(-13+i,-13+i)) end
	for _=1,n-15 do
		r=r+1 if r==10 then l,r=l+1,0 end
		for i=1,12 do b[i],c[i]=0,0 end
		for i=12,2,-1 do
			local t,u=a[i]*r+b[i],a[i]*l+c[i]
			b[i-1],b[i],c[i-1],c[i]=f(t/10),t%10,f(u/10),u%10
		end
		b[1],c[1]=(a[1]*r+b[1])%10,(a[1]*l+c[1])%10
		a[11],a[12]=0,b[12]
		for i=11,2,-1 do
			local t=a[i]+b[i]+c[i+1]
			a[i-1],a[i]=t>9 and 1 or 0,t%10
		end
		a[1]=(a[1]+b[1]+c[2])%10
	end
	return table.concat(a)
end, function (n)
	local r=1 for i=1,n do r=r*i end return r
end, io.stdin:read("*n")))
0