Prime Cryptarithm

The numbers are small enough that we just brute-force the problem.

def isGoodNum(num,values):
    for j in str(num):
        if not(int(j) in values): return False
    return True

def iterate(values):
    res = 0
    for a in range(100,999):
        if isGoodNum(a,values):
            for b in range(10,99):
                nums = [b,a*b,a*(b//10),a*(b%10)]
                if nums[1] < 10000 and nums[2] < 1000 and nums[3] < 1000:
                    for i in nums:
                        if not isGoodNum(i,values):
                            break
                    else:
                        res += 1
                        print(a,b)
    return res

def main():
    with open('crypt1.in','r') as fIn:
        values = list(map(int,fIn.read().split('\n')[1].split()))
    with open('crypt1.out','w') as fOut:
        fOut.write(str(iterate(values))+'\n')

main()