Problem:


Score : 300 points

Problem Statement

You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?

Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

Sample Input 1

575

Sample Output 1

4

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

Sample Input 2

3600

Sample Output 2

13

There are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.

Sample Input 3

999999999

Sample Output 3

26484



Sample input:
575


Sample output:
4

Submission status: Wrong Answer

Solution code:
import copy
mod = 10**9+1
def com(n,r,m):
    #a = math.factorial(n)%m
    a = 1
    for i in range(1,n+1):
        a *= i
        a %= m
    A = pow(a,m-2,m)
    
    
    b= copy.deepcopy(A)   
    for i in range(n,r,-1):
        b = (b*i)%m
    
    c = copy.deepcopy(A)
    for i in range(n,n-r,-1):
        c = (c*i)%m
       
    return (a*b*c)%m

n = input()
ans = 0
for i in range(3,len(n)):
    ans += 3**i-3*2**i+3
b = [3,5,7]
l = [0,0,0]
for i in range(len(n)):
    x = int(n[i])
    if not 0 in l:
        if (x<3):
            break
        elif (x==3):
            l[0]+=1
        elif (x==4):
            ans += 3**(len(n)-1-i)
            break
        elif (x==5):
            ans += 3**(len(n)-1-i)
            l[1]+=1
        elif (x==6):
            ans += 3**(len(n)-1-i)
            ans += 3**(len(n)-1-i)
            break
        elif (x==7):
            ans += 3**(len(n)-1-i)
            ans += 3**(len(n)-1-i)
            l[2]+=1
        else:
            ans += 3**(len(n)-1-i)
            ans += 3**(len(n)-1-i)
            ans += 3**(len(n)-1-i)
            break
        continue
    if (l[0]==0 and l[1]==0 or l[1]==0 and l[2]==0 or l[0]==0 and l[2]==0):
        if (x<3):
            break
        elif (x==3):
            l[0]+=1
        elif (x==4):
            ans += 3**(len(n)-1-i)-1
            break
        elif (x==5):
            ans += 3**(len(n)-1-i)-1
            l[1]+=1
        elif (x==6):
            ans += 3**(len(n)-1-i)-2**(len(n)-1-i)
            ans += 3**(len(n)-1-i)-2**(len(n)-1-i)
            break
        elif (x==7):
            ans += 3**(len(n)-1-i)-2**(len(n)-1-i)
            ans += 3**(len(n)-1-i)-2**(len(n)-1-i)
            l[2]+=1
        else:
            ans += 3**(len(n)-1-i)-2**(len(n)-1-i)
            ans += 3**(len(n)-1-i)-2**(len(n)-1-i)
            ans += 3**(len(n)-1-i)-2**(len(n)-1-i)
            break
        continue
    if (l[0]==0 or l[1]==0 or l[2]==0):
        if (x<3):
            break
        elif (x==3):
            l[0]+=1
        elif (x==4):
            ans += 3**(len(n)-1-i)-2*2**(len(n)-1-i)+1
            break
        elif (x==5):
            ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
            l[1]+=1
        elif (x==6):
            ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
            ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
            break
        elif (x==7):
            ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
            ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
            l[2]+=1
        else:
            ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
            ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
            ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
            break
        continue

    if (x<3):
        break
    elif (x==3):
        l[0]+=1
    elif (x==4):
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        break
    elif (x==5):
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        l[1]+=1
    elif (x==6):
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        break
    elif (x==7):
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        l[2]+=1
    else:
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        ans += 3**(len(n)-1-i)-3*2**(len(n)-1-i)+3
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
if N<357:
  print(0)
answer=[3,5,7]
for i in range(8):
  A=[i*10+3 for i in answer]
  C=[i*10+5 for i in answer]
  B=[i*10+7 for i in answer]
  answer.extend(A)
  answer.extend(B)
  answer.extend(C)
s=0
answer=list(set(answer))
for i in answer:
  if i<=N:
    if set(str(i))=={"3","5","7"}:
      s+=1
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())

count = 0


def calc(n, n3, n5, n7):
    global count
    if n > N:
        return
    if n < N and n3 and n5 and n7:
        count += 1
    calc(10 * n + 3, 1, n5, n7)
    calc(10 * n + 5, n3, 1, n7)
    calc(10 * n + 7, n3, n5, 1)


calc(0, 0, 0, 0)
print(count)

Submission status: Wrong Answer

Solution code:
def make753(n):
    ns = str(n)
    l = len(ns)* -1
    flg = True
    while flg:
        for i in range(-1, l-1, -1):
            if ns[i] == '3' or ns[i] == '5':
                ii = (i+1)*-1
                n += 10**ii*2
                flg = False
                break
            if ns[i] == '7':
                ii = (i+1)*-1
                n -= 10**ii*4
                flg = False
                continue
    ns = str(n)
    for j in range(len(ns)):
        if not ns[j] == '3':
            break
        if j == len(ns) - 1:
            n = 10*n+3
    return n


def check753(n):
    ns = str(n)
    l = len(ns)
    a = []
    for i in range(l):
        a.append(int(ns[i]))
    a = list(set(a))
    if len(a) == 3:
        return True
    else:
        return False

n = int(input())
a = 333
cnt = 0
if n < 333:
    print(0)
    exit()

while a <= n:
    a = make753(a)
    if check753(a):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def make753(n):
    ns = str(n)
    l = len(ns)* -1
    flg = True
    while flg:
        for i in range(-1, l-1, -1):
            if ns[i] == '3' or ns[i] == '5':
                ii = (i+1)*-1
                n += 10**ii*2
                flg = False
                break
            if ns[i] == '7':
                ii = (i+1)*-1
                n -= 10**ii*4
                flg = False
                continue
    ns = str(n)
    for j in range(len(ns)):
        if not ns[j] == '3':
            break
        if j == len(ns) - 1:
            n = 10*n+3
    return n


def check753(n):
    ns = str(n)
    l = len(ns)
    a = []
    for i in range(l):
        a.append(int(ns[i]))
    a = list(set(a))
    if len(a) == 3:
        return True
    else:
        return False

n = int(input())
a = 333
cnt = 0

while a <= n:
    a = make753(a)
    if check753(a):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
import bisect
N = int(input())

lst = ['3','5','7']
anslst = []
for i in range(1,10):
    for v in itertools.product(lst,repeat=i):
        x = Counter(str(v))
        if x['7'] >= 1 and x['5'] >= 1 and x['3'] >= 1:
            anslst.append(int(''.join(v)))
anslst.sort()
index = bisect.bisect_left(list(anslst), N)
print(index)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
import bisect
N = int(input())

lst = ['3','5','7']
anslst = set()
for i in range(1,10):
    for v in itertools.product(lst,repeat=i):
        x = Counter(str(v))
        if x['7'] >= 1 and x['5'] >= 1 and x['3'] >= 1:
            anslst.add(int(''.join(v)))

index = bisect.bisect_left(list(anslst), N)
print(index)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
import bisect
N = int(input())

lst = ['3','5','7']
anslst = []
for i in range(1,10):
    for v in itertools.product(lst,repeat=i):
        x = Counter(str(v))
        if x['7'] >= 1 and x['5'] >= 1 and x['3'] >= 1:
            anslst.append(int(''.join(v)))

index = bisect.bisect_left(anslst, N)
print(index)