結果

問題 No.16 累乗の加算
ユーザー nobigomunobigomu
提出日時 2018-04-25 01:33:02
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 965 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 5,360 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-10 05:14:41
合計ジャッジ時間 1,340 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,388 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,384 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(mpz_ptr);
void __gmpz_init_set_d(mpz_ptr, double);
void __gmpz_set_str(mpz_ptr, const char *, int);
void __gmpz_add(mpz_ptr, mpz_srcptr, mpz_srcptr);
void __gmpz_powm(mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr);
int __gmp_printf(const char *, ...);
]]

M.__gmp_printf("%Zd\n", (function (ct, n, x, _, s)
	local b,m,e,r,t = ct(),ct(),ct(),ct(),ct()
	M.__gmpz_init_set_d(b,x) M.__gmpz_init_set_d(m,n) M.__gmpz_init(e) M.__gmpz_init(r) M.__gmpz_init(t)
	for d in s:gmatch("%d+") do
		M.__gmpz_set_str(e,d,10) M.__gmpz_powm(r,b,e,m) M.__gmpz_add(t,t,r)
	end
	return t
end)(ffi.typeof("mpz_t"), 1000003, io.stdin:read("*n"), io.stdin:read("*l"), io.stdin:read("*l")))
0