"""
ID: ***
LANG: PYTHON3
TASK: crypt1
"""
fin = open ('crypt1.in', 'r')
fout = open ('crypt1.out', 'w')
N = int(fin.readline())
numS = 0
digits = list(map(int,fin.readline().split()))
#print(digits)
abc = list()
de = list()
def ifQualified(product, digits) -> bool:
for x in range(len(str(product))):
if int(str(product)[x]) not in digits:
return False
return True
#'abc'
for a in range(N):
for b in range(N):
for c in range(N):
abc.append(int("{}{}{}".format(digits[a],digits[b],digits[c])))
for d in range(N):
for e in range(N):
de.append(int("{}{}".format(digits[d],digits[e])))
for x in range(len(abc)):
for y in range(len(de)):
e = de[y]%10
d = de[y]//10
eabc = e*abc[x]
dabc = d*abc[x]
deabc = de[y]*abc[x]
if len(str(dabc))>3 or len(str(eabc))>3:
continue
if ifQualified(eabc, digits) and ifQualified(dabc, digits) and ifQualified(deabc, digits):
numS += 1
#print(abc[x], de[y], deabc)
fout.write("{}\n".format(str(numS)))
fout.close()
USACO 1.4 Python3 Prime Cryptarithm
最新推荐文章于 2024-02-01 10:39:25 发布