Skip to content

Instantly share code, notes, and snippets.

@cdfq152313
Last active April 19, 2017 19:11
Show Gist options
  • Save cdfq152313/4a210ac024c2dda5804a0400bbc0e443 to your computer and use it in GitHub Desktop.
Save cdfq152313/4a210ac024c2dda5804a0400bbc0e443 to your computer and use it in GitHub Desktop.
fact = [1, 1, 2, 6, 3, 1, 6]
base = [1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]
def lnzsdf(x):
result = 1
count = 0
cur = x
while cur != 0:
mod = cur % 7
result = result * fact[mod] * (base[count] ** mod) % 7
count += 1
cur /= 7
return result
if __name__ == '__main__':
num = int (raw_input() )
for i in range(0, num):
x = int ( raw_input())
print lnzsdf(x)
print 'Factorial'
fact = [1, 1]
for i in range(2,7):
cur = fact[-1] * i % 7
fact.append(cur)
print fact
print 'Base'
def stupid_lnzsdf(x):
t = 1
for i in range(1,x+1):
while i % 7 == 0:
i /= 7
t *= i
t %= 7
return t
base = list()
# you can find an array 1 6 1 6 1 6 ....
for i in range(0, 14):
x = stupid_lnzsdf(7 ** i)
print x
base.append(x)
print base
問:七進位234的階層答案
Ans:
從最低位4開始
fact[4] * base[0] *
乘上第二位數3
fact[3] base[1] *
乘上第三位數2
fact[2] * base[2]
最後整體7餘數
% 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment