Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yasuharu519/1281463 to your computer and use it in GitHub Desktop.
Save yasuharu519/1281463 to your computer and use it in GitHub Desktop.
GoogleCodeJamJapan2011 決勝 問題B.バクテリア増殖
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def file_open(filename):
T = 0
caseList = []
with open(filename) as f:
T = int(f.readline().strip())
for i in range(T):
value = [int(x) for x in f.readline().strip().split()]
caseList.append(tuple(value))
return caseList
def process(testList):
A, B, C = testList
if B < 2:
return pow(A, A, C)
else:
# first time
tmp = pow(A, A)
ans = pow(tmp, tmp, C)
return ans
def solve(caseList, filename):
f = open(filename, 'w')
for i, T in enumerate(caseList):
ans = process(T)
f.write("Case #" + str(i + 1) + ": " + str(ans) + "\n")
f.close()
def _test():
import doctest
doctest.testmod()
def main():
FILENAME = "B-small-attempt1.in"
OUTNAME = "outputBsmall.txt"
A = file_open(FILENAME)
solve(A, OUTNAME)
if __name__ == "__main__":
main()
#_test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment