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: Accepted

Solution code:
def cnct(lint,lim):
    global count
    lintlst=list(str(lint))
    if lint>lim:
        return True
    if lintlst.count("3") and lintlst.count("5") and lintlst.count("7"):
        count+=1
    cnct(lint*10+3,lim)
    cnct(lint*10+5,lim)
    cnct(lint*10+7,lim)
list753=[3,5,7]
count=0
b=int(input())
for a in list753:
    cnct(a,b)
print(count)

Submission status: Accepted

Solution code:
def cnct(lint,lim):
    global list753
    global list357
    lint1int=lint*10+3
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2int=lint*10+5
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3int=lint*10+7
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 

list753=[3,5,7]
list357=set()
k=int(input())
for b in list753:
    cnct(b,k)
print(len([x for x in list357 if list(str(x)).count("3")>0 and list(str(x)).count("5")>0 and list(str(x)).count("7")>0]))

Submission status: Accepted

Solution code:
N = int(input())

def calculate(s):
  if len(s) > 1:
    if int(s) > N:
      return 0
  
  ret = 1 if all([s.count(c) for c in '753']) else 0
  
  for i in '753':
    ret +=calculate(s+i)
  return ret

print(calculate(''))

Submission status: Accepted

Solution code:
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1int=lint*10+3
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2int=lint*10+5
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3int=lint*10+7
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 

def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
for b in list753:
    cnct(b,k)
for c in [x for x in list357]:
    if not D(c):
        list357.remove(c)
print(len(list357))

Submission status: Accepted

Solution code:
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1=str(lint)+"3"
    lint1int=int(lint1)
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2=str(lint)+"5"
    lint2int=int(lint2)
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3=str(lint)+"7"
    lint3int=int(lint3)
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 
    lint4="3"+str(lint)
    lint4int=int(lint4)
    if lint4int<=lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int,lim)
    lint5="5"+str(lint)
    lint5int=int(lint5)
    if lint5int<=lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int,lim)
    lint6="7"+str(lint)
    lint6int=int(lint6)
    if lint6int<=lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int,lim)
def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
count=0
for b in list753:
    cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print(len(list333))

Submission status: Accepted

Solution code:
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1=str(lint)+"3"
    lint1int=int(lint1)
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2=str(lint)+"5"
    lint2int=int(lint2)
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3=str(lint)+"7"
    lint3int=int(lint3)
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 
    lint4="3"+str(lint)
    lint4int=int(lint4)
    if lint4int<=lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int,lim)
    lint5="5"+str(lint)
    lint5int=int(lint5)
    if lint5int<=lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int,lim)
    lint6="7"+str(lint)
    lint6int=int(lint6)
    if lint6int<=lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int,lim)
def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
count=0
for b in list753:
    cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print(len(list333))

Submission status: Accepted

Solution code:
n = int(input())
d = int(len(str(n)))
c = 0
for k in range(3,d):
  c += 3**k-3*2**k+3
u = int(str(n)[0])
if u >= 8:
  c += 3**d-3*2**d+3
  print(c)
  exit()
if u >= 6:
  c += (3**(d-1)-2**d +1)*2
  i = 2*3**(d-1)
elif u >= 4:
  c += 3**(d-1)-2**d + 1
  i = 3**(d-1)
elif u <= 2:
  print(c)
  exit()
else:
  i = 0
x = [3,5,7]
while True:
  s = 0
  y = [0,0,0]
  p = i
  for j in range(d):
    s += x[p%3]*(10**j)
    y[p%3] = 1
    p = p//3
  if s <= n:
    if sum(y) == 3:
      c += 1
    i += 1
  else:
    break
print(c)

Submission status: Accepted

Solution code:
n=int(input())
def dfs(s):
    if int(s) > n:
        return 0
    if all(s.count(c)>0 for c in "753"):
        ret = 1
    else:
        ret = 0
    for c in "753":
        ret += dfs(s+c)
    return ret
print(dfs("0"))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


n = int(readline())


def dfs(s):
    if int(s) > n:
        return 0
    flag = True
    for check in '753':
        if s.count(check) <= 0:
            flag = False
    if flag:
        x = 1
    else:
        x = 0
    for check in '753':
        x += dfs(s + check)
    return x


print(dfs('0'))

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())

queue = deque()
queue.append(0)
ans = 0

while queue:
    a = queue.pop()
    if a > n:
        continue
    if all(str(a).count(str(i)) for i in [7, 5, 3]):
        ans += 1
    [queue.append(a * 10 + i) for i in [7, 5, 3]]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
import collections

def is753(s):
    c = collections.Counter(s)
    if c["3"] > 0 and c["5"] > 0 and c["7"] > 0 :
        if c["3"] + c["5"] + c["7"] == len(str(int(s))):
            return True
    return False

def f(s):
    if int(s) > n:
        return 0
    ans=0
    if is753(s):
        ans+=1

    return ans + f(s+"3")+ f(s+"5")+ f(s+"7")

print(f("0"))

Submission status: Accepted

Solution code:
n = int(input())
def dfs(s,n):
  count = 0
  if s > n:
    return count
  if str(3) in list(str(s)) and str(5) in list(str(s)) and str(7) in list(str(s)):
    count += 1
  count += dfs(10*s + 3,n)
  count += dfs(10*s + 5,n)
  count += dfs(10*s + 7,n)
  return count


print(dfs(3,n) + dfs(5,n) + dfs(7,n))

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    if all(s.count(c) > 0 for c in '753'):
        ret = 1
    else:
        ret = 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
count = 0

for i in range(1,len(str(N))+1):
  for j in product(['3','5','7'], repeat = i):
    s = ''.join(j)
    if '7' in s and '5' in s and '3' in s and int(s) <= N:
      count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
    if int(s) >N :
        return 0
    if all(s.count(c) > 0 for c in '753'):
        res=1
    else:
        res=0
    for c in '753':
        res += dfs(s+c)
    return res

print(dfs('0'))

Submission status: Accepted

Solution code:
import bisect

n = int(input())

num = [3, 5, 7]
last_num = [3, 5, 7]
tfs = [3, 5, 7]

for i in range(8):
    new_num = []
    for a in last_num:
        for b in tfs:
            new_num.append(a*10 + b)
    num += new_num
    last_num = new_num

num753 = []

for a in num:
    if len(set(str(a))) == 3:
        num753.append(a)

print(bisect.bisect_right(num753, n))

Submission status: Accepted

Solution code:
N = int(input())
cnt = []
def dfs(num):
    if num > N:
        return
    if str(num).count('3') >= 1 and str(num).count('5') >= 1 and str(num).count('7') >= 1:
        cnt.append(num)
    dfs(num * 10 + 3)
    dfs(num * 10 + 5)
    dfs(num * 10 + 7)
dfs(0)
print(len(cnt))

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
num753 = set()
q = deque([3,5,7])
while q:
    x = q.pop()
    if x <= 10**9:
        num753.add(x)
        q.append(x*10+3)
        q.append(x*10+5)
        q.append(x*10+7)
count = 0
for i in num753:
    if i <= n:
        lst = list(str(i))
        if "3" in lst and "5" in lst and "7" in lst:
            count += 1
print(count)

Submission status: Accepted

Solution code:
L = []
num = ["3", "5", "7"]
peak = 1
for i in range(10):
  for j in range(peak):
    T = ""
    S = [0, 0, 0]
    tmp = j
    for k in range(i):
      T = T[:] + num[tmp%3]
      S[tmp%3] += 1
      tmp //= 3
    if S[0] * S[1] * S[2] > 0:
      L.append(int(T))
  peak *= 3
L.sort()
N = int(input())
n = len(L)
l, c, r = 0, n // 2, n
pnt = 0
m = max(L)
if m <= N:
  print(n)
else:
  while L[pnt] <= N:
    pnt += 1
  print(pnt)

Submission status: Accepted

Solution code:
from itertools import product
def myketa(num):
  cc = 0
  while num > 0:
    num //= 10
    cc += 1
  return cc

n = int(input())
keta = myketa(n)
lst = []
for k in range(1, keta+1):
  lst += [''.join(i) for i in product('357', repeat=k)]
print(sum([int(x) <= n and len(set(x)) == 3 for x in lst]))

Submission status: Accepted

Solution code:
N=int(input())
def dfs(str):
  if int(str)>N:
    return 0
  if all(str.count(base)>0 for base in '753'):
    ans=1
  else:
    ans=0
  for base in '753':
    ans+=dfs(str+base)
  return ans
print(dfs('0'))

Submission status: Accepted

Solution code:
# bitDPやりたくなるけどあきらかにオーバーキル
# ふつうにDFSする
n = int(input())


def dfs(cur):
    ret = 0
    for m in ["3", "5", "7"]:
        nex = cur
        nex += m
        if int(nex) <= n:
            if "7" in nex and "5" in nex and "3" in nex:
                ret += 1
            ret += dfs(nex)
    return ret


print(dfs(""))

Submission status: Accepted

Solution code:
n = list(map(int,list(input())))
len_n = len(n)

dp = [[[0]*8 for i in range(2)] for j in range(len_n)]
base = [0,3,5,7]

for i in range(n[0]+1):
  temp = 0
  ans = 0

  
  if i == 3:
    temp = 1
    ans = 1
  elif i == 5:
    temp = 2
    ans = 1
  elif i == 7:
    temp = 4 
    ans = 1
  elif i == 0:
    temp = 0
    ans = 1
    
  dp[0][n[0] == i][temp] += ans 

for i in range(1,len_n):
  for j in range(2):
    for k in range(8):
      for l in base: 
        if (j == 1) and (n[i] < l):
          continue
          
        if (not(k == 0)) and (l == 0):
          continue
        
        temp = 0
        
        if l == 3:
          temp = 1
        elif l == 5:
          temp = 2
        elif l == 7:
          temp = 4
          
        dp[i][j & (n[i] == l)][k | temp] += dp[i-1][j][k]
        
print(dp[len_n-1][1][7] + dp[len_n-1][0][7])

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
    
    if int(s) > n:
        return 0

    if all(s.count(c) > 0 for c in ["7","5","3"]):
        ret = 1
    else:
        ret = 0

    for c in ["7","5","3"]:
        ret += dfs(s + c)

    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret
print(dfs('0'))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())

    d = deque([3,5,7])
    res = 0
    while 1:
        a = d.popleft()
        for i in [3,5,7]:
            b = a*10 + i
            if b <= n:
                d.append(b)
                b = str(b)
                if '3' in b and '5' in b and '7' in b:
                    res += 1
            else:
                print(res)
                exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import queue

N = int(input())

q = queue.Queue()
for i in [3,5,7]:
    q.put(i)
#print(q)

cnt = 0
while True:
    n = q.get()
    if n > N:
        break
    elif '3' in str(n) and '5' in str(n) and '7' in str(n):
        cnt += 1
        #print(n)
    q.put(n * 10 + 3)
    q.put(n * 10 + 5)
    q.put(n * 10 + 7)
print(cnt)

Submission status: Accepted

Solution code:
def next(n):
    # nの次に小さい、3と7と5しか出てこない数
    s = str(n)
    if s[-1] == "3":
        return int(s[:-1] + "5")
    if s[-1] == "5":
        return int(s[:-1] + "7")
    # s[-1] == "7"
    if len(s) == 1:
        return 33
    else:
        s = str(next(s[:-1]))
        return int(s + "3")

def is_753(n):
    # 3, 7, 5 がすべて表れているかを判定
    s = str(n)
    if "3" in s and "5" in s and "7" in s:
        return True
    return False

def next_753(n):
    # 次の753数を返す
    while True:
        n = next(n)
        if is_753(n):
            return n

N = int(input())
ans = 0
n = 357
while n <= N:
    ans += 1
    n = next_753(n)
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  se = set([0])
  ans = []
  for k in range(3,10):
    S = product(['3', '5', '7'], repeat=k)
    for s in S:
      if len(set(s)) == 3:
        i=0
        for j in s:
          i  = i*10 + int(j)
        ans.append(i)
  ans.sort()
  print(bisect(ans,n))
  
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
  if int(s)>n:
    return 0
  ret = 1 if all(s.count(c) for c in "753") else 0
  for c in '753':
    ret+=dfs(s+c)
  return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


tmp = []


def func(n):
    global tmp
    if n < 10**9:
        tmp.append(n)
        func(n*10+3)
        func(n*10+5)
        func(n*10+7)
    return tmp


N = int(input())
n = len(func(0))
func(0)
ans = 0
for i in range(n):
    if tmp[i] <= N:
        x = str(tmp[i])
        if ('3' in x) and ('5' in x)and('7' in x):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
nagoya = [3,5,7]
i = 1
if n < 357:
    print(0)
    exit()
ans = 0
while(i < 99):
    current = list(itertools.product(nagoya,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if len(set(str(h))) == 3:
            if n < h:
                print(ans)
                exit()
            else:
                ans += 1
    i += 1

Submission status: Accepted

Solution code:
n = int(input())
from itertools import product
ans = 0
for i in range(1, 11):
  for p in product("357", repeat=i):
    v = "".join(p)
    if "3" in v and "5" in v and "7" in v and int("".join(p)) <= n:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
cnt=[]
def dfs(pos,p):
    if p==0:
        #print(pos)
        if int("".join(pos))<=n and "3" in pos and "5" in pos and "7" in pos:
            cnt.append(pos)
    else:
        for j in [3,5,7]:
            dfs(pos+[str(j)],p-1)

if len(str(n))<=2:
    print(0)
    exit()

for i in range(3,len(str(n))+1):
    pos=[]
    p=i
    dfs(pos,p)
print(len(cnt))

Submission status: Accepted

Solution code:
n = int(input())

def generate(p):
    for i in [3, 5, 7]:
        yield p * 10 + i

nums = [3, 5, 7]
ans = 0
num = 0
p = 0

while num < n:
    for a in generate(nums[p]):
        nums.append(a)
        num = a
        if a <= n and set(list(str(a))) == set(list(str(357))):
            ans += 1
    p += 1

print(ans)

Submission status: Accepted

Solution code:
def DFS(n):
    if len(n)>=3 and len(set(list(n))&{"3","5","7"})==3:
        A.append(int(n))
    if len(n)<10:
        for i in ("3","5","7"):
            DFS(n+i)


n=int(input())
A=[]
for i in ("3","5","7"):DFS(i)
A.sort()

cnt=0
while 1:
    if A[cnt]<=n:cnt +=1
    else:break
print(cnt)

Submission status: Accepted

Solution code:
def dfs(s, n):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '357') else 0
    for c in '357':
        ret += dfs(s + c, n)
    return ret


def main():
    from collections import deque
    n = int(input())
    ans = dfs('0', n)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def dfs(n,s):
    if int(s)>n:
        return 0
    res=0
    if s.count('7') and s.count('5') and s.count('3')>0:
        res+=1
    for c in '753':
        res+=dfs(n,s+c)
    return res

n=int(input())
print(dfs(n,'0'))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = str(n)
m = len(str(n))

lst = [3,5,7]
que = deque([3,5,7])
for _ in range(3**m):
    x = que.popleft()
    for j in [3,5,7]:
        que.append(int(str(x)+str(j)))
        lst.append(int(str(x)+str(j)))

ans = 0
for i in lst:
    if i > n:
        break
    cnt = [0]*3
    for j in str(i):
        cnt[(int(j)-1)//3] += 1
    for j in cnt:
        if j == 0:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
import os
import re
import datetime
import bisect

def DFS(tmpN, N, bitFlags):
    if(tmpN > N):
        return 0

    countAll = 0
    if bitFlags == 0b111:
        countAll += 1

    countAll += DFS(tmpN * 10 + 3, N, bitFlags | 0b100)
    countAll += DFS(tmpN * 10 + 5, N, bitFlags | 0b010)
    countAll += DFS(tmpN * 10 + 7, N, bitFlags | 0b001)

    return countAll

### main ###
 
N = int(input())

bitFlags = 0b000
result = DFS(0, N, bitFlags)

print(result)

Submission status: Accepted

Solution code:

def dfs(n,lst,s):
	if int(s) >n:
		return 
	if all([c in s for c in "753"]):
		lst.append(s)
	for c in "753":
		dfs(n,lst,s+c)

lst=[]
n =int(input())
for c in "753":
	dfs(n,lst,c)
print(len(lst))

Submission status: Accepted

Solution code:
# 解説コード
N = int(input())

def dfs(s): # 文字列 s で始まる七五三数の個数
  if int(s) > N:
    return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
  for c in '753':
    ret += dfs(s + c)
  return ret

print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく

Submission status: Accepted

Solution code:
from itertools import product

def read():
    N = int(input())
    return N,

def solve(N):
    count = 0
    for i in range(3, 10):
        for x in product('357',repeat=i):
            if all(x.count(d) for d in '357'):
                if int(''.join(x), 10) <= N:
                    count += 1
    return count

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

Solution code:
from itertools import product

def read():
    N = int(input())
    return N,

def solve(N):
    count = 0
    for i in range(3, 10):
        for x in product('357',repeat=i):
            if '3' in x and '5' in x and '7' in x:
                if int(''.join(x), 10) <= N:
                    count += 1
    return count

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)

N = 0
ans = 0


def isOK(n):
    m = set()
    for s in str(n):
        m.add(s)
    if len(m) != 3:
        return False
    if '3' in m and '5' in m and '7' in m:
        return True
    return False


def rec(n):
    global ans
    global N
    if n > N:
        return
    if isOK(n):
        ans += 1
    rec(n * 10 + 3)
    rec(n * 10 + 5)
    rec(n * 10 + 7)


def solve():
    global N
    N = Scanner.int()
    rec(0)
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0

    ret = 1 if all(s.count(c) > 0 for c in '753') else 0  # s自体が753数なら+1
    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs('0'))

Submission status: Accepted

Solution code:
import itertools

if __name__ == "__main__":
    n = input()

    if len(n) < 3:
        print(0)
        exit()

    ans = 0
    seq = ['0', '3', '5', '7']

    tmp = list(itertools.product(seq, repeat=len(n)))

    for t in tmp:
        if int(''.join(t)) <= int(n):
            a = str(int(''.join(t)))
            if '0' not in a and len(set(a)) == 3:
                ans += 1

    print(ans)

Submission status: Accepted

Solution code:
N=int(input())

def dfs(s):
  if int(s)>N:
    return 0
  ret=1 if all(s.count(c)>0 for c in '753') else 0
  for c in '753':
    ret+=dfs(s+c)
  return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

ans=0

chk=True
cnt=0
while chk:
    cnt+=1
    for i in product([3,5,7],repeat=cnt):
        if 3 in i and 5 in i and 7 in i:
            if n>=int("".join(map(str, i))):
                ans+=1
            else:
                chk=False
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

m = input()
x = int(m)
n = len(m)
d = [3,5,7]
ans2 = []

def dfs( n , s ):
    if s // (10**(n-1)) != 0:
        ans.append(s)
        return
    else:
        for j in d:
            dfs( n , s*10+j )
            
def kak(n,lis):
    for l in range(len(lis)):
        a = [0] * 10
        c = lis[l]
        for _ in range(n):
            b = c % 10
            a[b] += 1
            c //= 10
            
        if a[3] != 0 and a[5] != 0 and a[7] != 0:
            ans2.append(lis[l])
            
for i in range(n+1):
    ans = []
    dfs(i,0)
    kak(i,ans)

ta = 0
for i in ans2:
    if x >= i:
        ta += 1
        
print(ta)

Submission status: Accepted

Solution code:
n = int(input())
s = [3,5,7]

ans = 0
a = [""]
for i in range(len(str(n))):
    b = []
    for j in a:
        for k in s:
            k1 = int(j + str(k))
            b.append(str(k1))
            if k1 <= n and "3" in str(k1) and "5" in str(k1) and "7" in str(k1):
                ans += 1
    a = b

print(ans)