-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path032.py
More file actions
33 lines (24 loc) · 735 Bytes
/
032.py
File metadata and controls
33 lines (24 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# ugly solution, but still pass all the test cases
# the for loop bounds can be tightened
from math import sqrt
def check_pandigit(a, b, c, l):
pandigit = [True] * l
for s in [a, b, c]:
for index in range(len(s)):
num = ord(s[index]) - 49
if l > num >= 0 and pandigit[num]:
pandigit[num] = False
else:
return False
return not any(pandigit)
N = int(input())
product = N // 2
limit = int(sqrt(10 ** product - 1))
l = set([])
for i in range(1, limit):
for j in range(1, 10 ** product):
if len(str(i*j)) > product:
break
if check_pandigit(str(i), str(j), str(i * j), N):
l.add(i * j)
print(sum(l))