結果

問題 No.16 累乗の加算
ユーザー nobigomunobigomu
提出日時 2018-04-25 01:37:21
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,036 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 5,280 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 05:14:59
合計ジャッジ時間 1,231 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
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_mod(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
	M.__gmpz_mod(t,t,m)
	return t
end)(ffi.typeof("mpz_t"), 1000003, io.stdin:read("*n"), io.stdin:read("*l"), io.stdin:read("*l")))
0