結果

問題 No.793 うし数列 2
ユーザー 826814741_6826814741_6
提出日時 2019-03-07 17:03:03
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 19:25:58
合計ジャッジ時間 1,180 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 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 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 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 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 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;

int __gmp_printf(const char *, ...);
int __gmp_scanf(const char *, ...);

void __gmpz_init(mpz_ptr);
void __gmpz_set_d(mpz_ptr, double);
void __gmpz_set_si(mpz_ptr, long);
void __gmpz_set_str(mpz_ptr, const char *, int);
void __gmpz_set_ui(mpz_ptr, unsigned long);

void __gmpz_mod(mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_mul(mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_powm(mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr);
void __gmpz_sub(mpz_ptr, mpz_srcptr, mpz_srcptr);
]]

function mpz(a, b)
	local c=ffi.new("mpz_t")
	M.__gmpz_init(c)
	if type(a)=="number" then M.__gmpz_set_d(c,a)
	elseif type(a)=="string" then M.__gmpz_set_str(c,a,b==nil and 10 or b)
	elseif ffi.istype(0LL,a) then M.__gmpz_set_si(c,a)
	elseif ffi.istype(0ULL,a) then M.__gmpz_set_ui(c,a)
	end
	return c
end

do
local D = 1000000007
local a,b,d,n = mpz(),mpz(),mpz(D),mpz()

M.__gmp_scanf("%Zd", n)

M.__gmpz_powm(a, mpz(10), n, d)
M.__gmpz_mul(a, a, mpz(4))
M.__gmpz_mod(a, a, d)
M.__gmpz_sub(a, a, mpz(1))

M.__gmpz_powm(b, mpz(3), mpz(D-2), d)

M.__gmpz_mul(a, a, b)
M.__gmpz_mod(a, a, d)

M.__gmp_printf("%Zd\n", a)
end
0