Merge branch 'master' of github.com:failedxyz/easyctf

This commit is contained in:
Jacob Magnuson 2017-03-11 06:47:51 +00:00
commit 00ed60e2dd
3 changed files with 54 additions and 0 deletions

11
library/generator.py Normal file
View file

@ -0,0 +1,11 @@
import random
C = input()
if C==1:
print 1
elif C==2:
print 2
elif C==3 or C==4:
print random.randint(3, 100)
else:
print random.randint(2**(C**3-1), 2**(C**3))

39
library/grader.py Normal file
View file

@ -0,0 +1,39 @@
x = input() + 1
mat = [[0,0,1,0],[0,1,0,1],[1,0,2,0],[0,2,0,1]]
mod = 10**9+7
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
def matmult(mtx_a, mtx_b, mod):
tpos_b = zip( *mtx_b)
rtn = [[ sum( ea*eb for ea,eb in zip(a,b))%mod for b in tpos_b] for a in mtx_a]
return rtn
def trace(A):
return sum(A[j][j] for j in range(len(A)))
def matpow(A, p):
ret = A
for bit in bin(p)[3:]:
ret = matmult(ret, ret, mod)
if bit=='1':
ret = matmult(ret, A, mod)
return ret
inv4 = modinv(4, mod)
ans = trace(matpow(mat, x))%mod
ans = (ans * inv4)% mod
print ans

View file

@ -28,3 +28,7 @@ Output:
``` ```
1 1
``` ```
Explanation:
If you understand the word 'ok', you can understand the word 'blah'. If you understand 'ok' and 'blah', you can understand 'iz'. 'iz', and 'ok' lets you understand 'yiq'. 'yiq', 'iz', and 'blah' let you understand 'arggiq'.