結果
| 問題 |
No.420 mod2漸化式
|
| コンテスト | |
| ユーザー |
nobigomu
|
| 提出日時 | 2018-04-25 19:30:35 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,034 bytes |
| コンパイル時間 | 248 ms |
| コンパイル使用メモリ | 5,376 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 21:04:37 |
| 合計ジャッジ時間 | 1,234 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 35 |
ソースコード
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")))
nobigomu