language: Python 3 (python-3.1.2)
date: 105 days 0 hours ago
link:
visibility: public
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
list4 = [4, 44, 444, 4444, 44444]
list7 = [7, 77, 777, 7777, 77777]
list10 = [10, 100, 1000, 10000, 100000]
index = -1
 
def equals(x, y):
    for i in range(index, -1, -1):
        mod1 = x % list10[i]
        mod2 = y % list10[i]
        if ((mod1 > list4[i]) and (mod1 <= list7[i])):
            group1 = 2
        else:
            group1 = 1 
        if ((mod2 >= list4[i]) and (mod2 < list7[i])):
            group2 = 1
        else:
            group2 = 2
        if (group1 == group2):
            return false
    return true
    
t = int(input(''))
for i in range(t):
        n = int(input(''))
        result = 0
        for j in range(1, n+1):
             for k in range(j, n+1):
                 if equals(j, k):
                     result += 1
        print(result)