-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project Euler #43: Sub-string divisibility.py
71 lines (67 loc) · 1.65 KB
/
Project Euler #43: Sub-string divisibility.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Author : Tonmoy M
# Author URI: https://qinetique.github.io
# Problem : Project Euler #43: Sub-string divisibility
# Problem Domain: HackerRank
# Problem URI: https://www.hackerrank.com/contests/projecteuler/challenges/euler043/problem?isFullScreen=true
from itertools import permutations
def divs(n):
sp = []
for i in permutations(range(0, n + 1)):
s = ''.join(map(str, i))
sp.append(s)
total = 0
for s in sp:
if len(s[1:4]) == 3:
if int(s[1:4]) % 2 == 0:
pass
else:
continue
else:
pass
if len(s[2:5]) == 3:
if int(s[2:5]) % 3 == 0:
pass
else:
continue
else:
pass
if len(s[3:6]) == 3:
if int(s[3:6]) % 5 == 0:
pass
else:
continue
else:
pass
if len(s[4:7]) == 3:
if int(s[4:7]) % 7 == 0:
pass
else:
continue
else:
pass
if len(s[5:8]) == 3:
if int(s[5:8]) % 11 == 0:
pass
else:
continue
else:
pass
if len(s[6:9]) == 3:
if int(s[6:9]) % 13 == 0:
pass
else:
continue
else:
pass
if len(s[7:10]) == 3:
if int(s[7:10]) % 17 == 0:
pass
else:
continue
else:
pass
total += int(s)
return total
if __name__ == '__main__':
n = int(input())
print(divs(n))