結果
問題 | No.167 N^M mod 10 |
ユーザー |
![]() |
提出日時 | 2018-05-29 00:34:22 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 12 ms / 1,000 ms |
コード長 | 1,398 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 5,120 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-22 01:45:33 |
合計ジャッジ時間 | 1,195 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
local ffi = require 'ffi'local M = ffi.load 'ssl'ffi.cdef [[typedef struct bignum_st {uint64_t *d;int top;int dmax;int neg;int flags;} BN;typedef BN * BN_ptr;typedef const BN * BN_srcptr;BN_ptr BN_new(void);void BN_free(BN_ptr);int BN_set_word(BN_ptr, uint64_t);int BN_dec2bn(BN_ptr *, const char *);char * BN_bn2dec(BN_srcptr);void CRYPTO_free(void *, const char *, int);typedef struct bignum_pool_item {BN vals[16];struct bignum_pool_item *prev, *next;} BN_POOL_ITEM;typedef struct bignum_pool {BN_POOL_ITEM *head, *current, *tail;unsigned used, size;} BN_POOL;typedef struct bignum_ctx_stack {unsigned int *indexes;unsigned int depth, size;} BN_STACK;typedef struct bignum_ctx {BN_POOL pool;BN_STACK stack;unsigned int used;int err_stack;int too_many;int flags;} BN_CTX;typedef BN_CTX * BN_CTX_ptr;BN_CTX_ptr BN_CTX_new(void);void BN_CTX_free(BN_CTX_ptr);int BN_mod_exp(BN_ptr, BN_srcptr, BN_srcptr, BN_srcptr, BN_CTX_ptr);]]local ct = ffi.typeof 'BN_ptr[1]'print((function (n, m)local r,mod,ctx=ffi.gc(M.BN_new(),M.BN_free),ffi.gc(M.BN_new(),M.BN_free),ffi.gc(M.BN_CTX_new(),M.BN_CTX_free)M.BN_dec2bn(n,io.stdin:read("*l"))M.BN_dec2bn(m,io.stdin:read("*l"))M.BN_set_word(mod,10ULL)M.BN_mod_exp(r, n[0], m[0], mod, ctx)return ffi.string(ffi.gc(M.BN_bn2dec(r),function (a) M.CRYPTO_free(a,"",0) end))end)(ct(), ct()))