結果

問題 No.420 mod2漸化式
ユーザー nobigomunobigomu
提出日時 2018-04-25 19:30:35
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,034 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 5,308 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 05:29:34
合計ジャッジ時間 1,555 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 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,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local ffi = require 'ffi'
local M = ffi.load 'gmp'

ffi.cdef [[
typedef unsigned long mp_limb_t;
typedef struct {
        int _mp_alloc;
        int _mp_size;
        mp_limb_t * _mp_d;
} __mpz_struct;
typedef __mpz_struct mpz_t[1];
typedef const __mpz_struct * mpz_srcptr;
typedef __mpz_struct * mpz_ptr;
void __gmpz_init_set_d(mpz_ptr, double);
void __gmpz_divexact(mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_mul_si(mpz_ptr, mpz_srcptr, long);
int __gmp_printf(const char *, ...);
]]

M.__gmp_printf((function (f, g, x)
	if x==0 then return "1 0\n" end
	if x>31 then return "0 0\n" end
	return "%Zd %Zd\n", f(31,x), f(30,x-1,g)
end)(function (n, r, f)
	local tn,tr = ffi.new("mpz_t"),ffi.new("mpz_t")
	M.__gmpz_init_set_d(tn,1) M.__gmpz_init_set_d(tr,1)
	if n-r<r then r=n-r end
	n,r = n+1LL,r+0LL
	while r>0LL do M.__gmpz_mul_si(tn,tn,n-r) M.__gmpz_mul_si(tr,tr,r) r=r-1LL end
	M.__gmpz_divexact(tn,tn,tr)
	return f~=nil and f(tn) or tn
end, function (tn)
	M.__gmpz_mul_si(tn,tn,2LL^31-1LL)
	return tn
end, io.stdin:read("*n")))
0