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:
N = int(input())

def dfs(n):
    if N < int(n):
        return 0

    ansB = True
    for i in '753':
        if n.count(i) == 0:
            ansB = False
            break
    ans = 0
    if ansB:
        ans = 1

    for i in '753':
        ans += dfs(n + i)
    return ans

print(dfs('0'))

Submission status: Accepted

Solution code:
n = input()
No753 = ['3','5','7']
for i in range(len(n)-1):
    No753_plus = []
    for no753 in No753:
        No753_plus += ['3' + no753]
        No753_plus += ['5' + no753]
        No753_plus += ['7' + no753]
    No753 += No753_plus
No75 = ['5','7']
for i in range(len(n)-1):
    No75_plus = []
    for no75 in No75:
        No75_plus += ['5' + no75]
        No75_plus += ['7' + no75]
    No75 += No75_plus
No53 = ['3','5']
for i in range(len(n)-1):
    No53_plus = []
    for no53 in No53:
        No53_plus += ['3' + no53]
        No53_plus += ['5' + no53]
    No53 += No53_plus
No37 = ['3','7']
for i in range(len(n)-1):
    No37_plus = []
    for no37 in No37:
        No37_plus += ['3' + no37]
        No37_plus += ['7' + no37]
    No37 += No37_plus
No753 = set(No753)-(set(No75)|set(No53)|set(No37))
count = 0
for no753 in No753:
    if int(no753) <= int(n):
        count += 1
print(count)

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline

N = int(input())

counter = 0

def func(cur=0, use=0):
    global counter
    if cur > N:
        return None
    if use == 0b111:
        counter += 1
    func(cur * 10 + 7, use | 0b001)
    func(cur * 10 + 5, use | 0b010)
    func(cur * 10 + 3, use | 0b100)

func()
print(counter)

Submission status: Accepted

Solution code:
n = int(input())

nana_go_sans = [{357, 375, 537, 573, 735, 753}]

order = len(str(n))
for i in range(3, order):
    nana_go_san = set()
    nana_go_san.add(int("3" + "5" * (i - 1) + "7"))
    nana_go_san.add(int("3" + "7" * (i - 1) + "5"))
    nana_go_san.add(int("5" + "3" * (i - 1) + "7"))
    nana_go_san.add(int("5" + "7" * (i - 1) + "3"))
    nana_go_san.add(int("7" + "3" * (i - 1) + "5"))
    nana_go_san.add(int("7" + "5" * (i - 1) + "3"))
    for num in nana_go_sans[i - 3]:
        nana_go_san.add(int("3" + str(num)))
        nana_go_san.add(int("5" + str(num)))
        nana_go_san.add(int("7" + str(num)))
        nana_go_san.add(int(str(num) + "3"))
        nana_go_san.add(int(str(num) + "5"))
        nana_go_san.add(int(str(num) + "7"))
    nana_go_sans.append(nana_go_san)

count = 0
for nana_go_san in nana_go_sans:
    for num in nana_go_san:
        if num <= 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:
from itertools import product

if __name__ == '__main__':
    N = int(input())
    count = 0
    digits = len(str(N))
    
    for n in range(1, digits+1):

        for t in product('357', repeat=n):
            num = ''.join(t)
            if int(num) <= N:
                if '3' in num and '5' in num and '7' in num:
                    count += 1
    print(count)

Submission status: Accepted

Solution code:
num753=[]
def checkall(n):
    flag = [0,0,0]
    while n > 0:
        if n % 10 == 3:
            flag[0] = 1
        elif n % 10 == 5:
            flag[1] = 1
        elif n % 10 == 7:
            flag[2] = 1
        else:
            pass
        n = n // 10
    return flag == [1,1,1]

def makelist(n,list1):
    if n > 10**9:
        return
    n3 = 10*n+3
    list1.append(n3)
    makelist(n3,list1)
    n5 = 10*n+5
    list1.append(n5)
    makelist(n5,list1)
    n7 = 10*n+7
    list1.append(n7)
    makelist(n7,list1)

makelist(0,num753)

N = int(input())
ans = 0
for x in num753:
    if x <= N and checkall(x):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = input()
l = list()
cnt = 0
def decide(digit,cur):
  if digit==0:
    l.append(cur)
    return
  decide(digit-1,cur+"3")
  decide(digit-1,cur+"5")
  decide(digit-1,cur+"7")
  return
for i in range(1,len(n)+1):
  decide(i,"")
n = int(n)
for x in l:
  if "3" not in x or "5" not in x or "7" not in x:
    continue
  if int(x)<=n:
    cnt += 1
print(cnt)

Submission status: Accepted

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

depth = len(str(n)) 
ans = 0

def search(s, i):
  if s != '':
    if int(s) <= n and '3' in s and '5' in s and '7' in s:
      global ans
      ans += 1
  if i != 0:
    for _a in a:
      search(s + _a, i - 1)

search('', depth)

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n=int(input())

ans = 0
for i in range(3, 10):
    for s in product('357', repeat=i):
        if len(set(s)) < 3:
            continue
        num = int(''.join(s))
        if  num > n:
            break
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# DP Solution (DP[...] = Bool if values which satisfy ... exist)
from itertools import product

N_str = input()
len_N = len(N_str)
N = int(N_str)

# DP Initialization
dp = [[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
      for _ in range(len_N)]
# dp[digit][is_max][is_3][is_5][is_7]

# "non 3, 5, 7" and "not max" values exist
for l in range(len_N):
    dp[l][0][0][0][0] = 1


# DP at 0 digit
for m in range(10):
    digit_0 = int(N_str[0])
    if m > digit_0:
        continue
    if m in [3, 5, 7]:
        dp[0][digit_0 == m][m == 3][m == 5][m == 7] = 1

# Current DP inherits last DP values
for l, m, n, o, p in product(range(len_N - 1), range(10), range(2), range(2),
                             range(2)):
    if m in [3, 5, 7]:
        digit_lp1 = int(N_str[l + 1])
        dp[l+1][0][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][0][n][o][p]

        if digit_lp1 < m:
            continue

        dp[l+1][digit_lp1 == m][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][1][n][o][p]

print(dp[-1][0][1][1][1] + dp[-1][1][1][1][1])

Submission status: Accepted

Solution code:
import itertools
n=int(input())
a=0
for i in range(3,len(str(n))+1):
    for p in itertools.product((3,5,7),repeat=i):
        if (3 in p)and(5 in p)and(7 in p):
            if int("".join(list(map(str,p))))<=n:
                a+=1
print(a)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    import itertools
    from bisect import bisect_left,bisect
    L=[]

    S = "753"
    m = 6
    for i in range(3,10):
        for j in itertools.product(S, repeat=i):
            flag7 = 0
            flag5 = 0
            flag3 = 0
            tmp = ""
            for s in j:
                if s == "7":
                    flag7 = 1
                elif s == "5":
                    flag5 = 1
                elif s == "3":
                    flag3 = 1
                tmp += s
            if flag3 == flag5 == flag7 == 1:
                tmp = int(tmp)
                L.insert(bisect_left(L,tmp), tmp)
    ans = bisect(L,N)
    print(ans)


main()

Submission status: Accepted

Solution code:
n=int(input())
cnt=0
l=['3','5','7']
def sol(x,c):
    global cnt
    if int(x)<=n and all(y in x for y in l):
        cnt+=1
    if c<9:
        for y in l:
            sol(x+y,c+1)
sol('0',0)
print(cnt)

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())

stack = deque()
num_753 = 0


def dfs():
    global stack, num_753

    s = stack.pop()

    if int(s) > N:
        return

    is_contained = 1 if all(s.count(c) > 0 for c in '753') else 0
    num_753 += is_contained

    for next_s in '357':
        stack.append(s + next_s)


stack.append('0')
while stack:
    dfs()

# Output
print(num_753)

Submission status: Accepted

Solution code:
# ABC114 C - 755
N = int(input())

def rep(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 += rep(s + c)
    return ret

print(rep('0'))

Submission status: Accepted

Solution code:
n = int(input())

def dts(s):
  if int(s) > n:
    return 0
  ret = 1 if all(s.count(_) for _ in '753') else 0
  for i in '753':
    ret += dts(s+i)
  return ret
  
print(dts('0'))

Submission status: Accepted

Solution code:
n=int(input())

def make_num(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+=make_num(s+c)
  return ret

print(make_num('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'):
    t = 1
  else:
    t = 0
  for c in '753':
    t += dfs(s+c)
  return t

print(dfs('0'))

Submission status: Accepted

Solution code:
n = input()

def abc(s):
  t = all(('3' in s, '5' in s, '7' in s))
  if len(s) < len(n):
    return abc(s+'3') + abc(s+'5') + abc(s+'7') + t
  elif s <= n:
    return t
  else:
    return 0

print(abc(''))

Submission status: Accepted

Solution code:
N = int(input())
scg = ["3", "5", "7"]
s = []
res = []
s += scg
while len(s) > 0:
  p = s.pop()
  for i in range(3):
    q = p + scg[i]
    if int(q) <= N:
      s.append(q)
      tfs = [0, 0, 0]
      for i in range(len(q)):
        if q[i] == "3":
          tfs[0] = 1
        elif q[i] == "5":
          tfs[1] = 1
        elif q[i] == "7":
          tfs[2] = 1
      if min(tfs) != 0:
        res.append(q)
print(len(res))

Submission status: Accepted

Solution code:
import itertools

def seven_five_five(n):
    s = list(str(n))
    len_s = len(s)
    semi_753 = []
    for j in range(3,len_s+1):
        for i in itertools.product(['3','5','7'],repeat=j):
            l = ''.join(i)
            #print l
            semi_753.append(l)

    target = [i for i in semi_753 if int(i) > 356 and int(i) <= n]
    #print target
    count = 0
    for i in target:
        v = str(i)
        flag = [False,False,False]
        for j in list(v):
            if j == '7':
                flag[0] = True
            elif j == '5':
                flag[1] = True
            elif j == '3':
                flag[2] = True
            else:
                break

            if flag[0] and flag[1] and flag[2]:
                #print i
                count += 1
                break
    print count
if __name__ == '__main__':
    n =  int(raw_input())
    seven_five_five(n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-                                                                              

N = int(input())

def count753(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 += count753(s + c)
    return ret

print(count753("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:
# 2019/08/27

n=int(input())
ln=len(str(n))
sft='7530'
cnt=0
def dfs(ln,s):
    global cnt
    if ln==0:
        if '7' in s and '5' in s and '3' in s:
            if '0' in str(int(s)):return
            if n>=int(s):cnt+=1
        return
    for e in sft:
        dfs(ln-1,s+e)
dfs(ln,'')

print(cnt)

Submission status: Accepted

Solution code:
N = input()
cnt = 0

if int(N) < 357:
    print(0)
    exit()

def solve(s):

    global cnt
    

    if len(s) >= 3:
        if int(s) > int(N):
            return

        n7 = s.count("7")
        n5 = s.count("5")
        n3 = s.count("3")

        if n7 >= 1 and n5 >= 1 and n3 >= 1 and n7+n5+n3 == len(s) and int(s) <= int(N):
            cnt += 1
        
    solve(s+"7")
    solve(s+"5")
    solve(s+"3")

solve("")
print(cnt)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc114/tasks/abc114_c
# C - 755
import itertools

n = int(input().split()[0])
k = len(str(n))
c = 0

if k >= 3:
    for j in range(3, k+1):
        p_gen = itertools.product([3, 5, 7], repeat=j)
        for p in p_gen:
            x = 0
            for k_i in range(j):
                x += p[k_i] * 10**k_i
            if x <= n and len(set(list(str(x)))) == 3:
                c += 1

print(c)

Submission status: Accepted

Solution code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = input()
num = int(n)
l = len(n)
li = ['3', '5', '7']
keta = [[] for i in range(l)]
keta[0] = li
for i in range(1, l):
    for kazu in keta[i-1]:
        for n in li:
            keta[i].append(kazu + n)
ct = 0
for i in range(l):
    for n in keta[i]:
        if '3' in n and '5' in n and '7' in n and int(n) <= num:
            ct += 1
print(ct)

Submission status: Accepted

Solution code:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(int, input().split())

tmp = str(n)
length = len(tmp)

def dfs(cnt, num, sev, fiv, thr):
    if cnt == 0:
        return 1 if n >= num and sev*fiv*thr > 0 else 0

    sevp = dfs(cnt-1, num + 7*(10**(cnt-1)), sev + 1, fiv, thr)
    fivp = dfs(cnt-1, num + 5*(10**(cnt-1)), sev, fiv + 1, thr)
    thrp = dfs(cnt-1, num + 3*(10**(cnt-1)), sev, fiv, thr + 1)

    zerop = 0
    if num == 0:
        zerop = dfs(cnt - 1, num , sev, fiv, thr)

    return sevp + fivp + thrp + zerop

print(dfs(length, 0, 0, 0, 0))

Submission status: Accepted

Solution code:
N = int(input())

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

dfs('0')
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
result = 0
q = list('753')
while q:
  s = q.pop(0)
  if int(s) > n:
    continue
  if all(s.count(c) > 0 for c in '753'):
    result += 1
  q.extend([s + c for c in '753'])
print(result)

Submission status: Accepted

Solution code:
n = int(input())
result = 0
q = list('753')
while q:
  s = q.pop()
  if int(s) > n:
    continue
  if all(s.count(c) > 0 for c in '753'):
    result += 1
  q.extend([s + c for c in '753'])
print(result)

Submission status: Accepted

Solution code:
N = input()
l = ['3', '5', '7']
L = ['3', '5', '7']
temp = []
d = len(N)
N = int(N)


if N - 357 < 0:
    print(0)
    exit()

#d-1桁以下の753数
a = 0
for i in range(3, d):
    a += 3 ** i - 3 * (2 ** i - 2) - 3

#d桁の753数
for k in range(d - 1):
    for i in L:
        for j in l:
            temp.append(i + j)
    L.clear()
    L.extend(temp)
    temp.clear()
L = [i for i in L if '3' in i and '5' in i and '7' in i]

count = 0
for i in L:
    if int(i) <= N:
        count += 1
print(a + count)

Submission status: Accepted

Solution code:
import heapq
import sys
import collections
input = sys.stdin.readline

def solve():
  n = int(input())
  query = collections.deque([3,5,7])
  template = []
  while query:
    tmp = query.popleft()
    tmp3 = str(tmp*10+3)
    if tmp3.count("3") and tmp3.count("5") and tmp3.count("7"):
      template.append(int(tmp3))
    tmp5 = str(tmp*10+5)
    if tmp5.count("3") and tmp5.count("5") and tmp5.count("7"):
      template.append(tmp5)
    tmp7 = str(tmp*10+7)
    if tmp7.count("3") and tmp7.count("5") and tmp7.count("7"):
      template.append(tmp7)
    if int(tmp3) <= n:
      query.append(int(tmp3))
    if int(tmp5) <= n:
      query.append(int(tmp5))
    if int(tmp7) <= n:
      query.append(int(tmp7))
  template2 = list(set(template))
  ans = 0
  for i in template2:
    if int(i) <= n:
      ans += 1
  print(ans)
   
      
    
solve()

Submission status: Accepted

Solution code:
N = int(input())
 
def search(i,j,k,val) :
    ret = 0 
    if val > N :
        return 0
    elif i > 0 and j > 0 and k > 0 and val<=N:
        ret = 1 
    else :
        ret = 0 
    ret += search(i+1,j,k,val*10+3)
    ret += search(i,j+1,k,val*10+5)
    ret += search(i,j,k+1,val*10+7)
    return ret
print(search(0,0,0,0))

Submission status: Accepted

Solution code:
X=input()
lst = [int(s) for s in list(X)]
N=len(lst)
X=int(X)
ans=0
#N桁より小さい753数を足す
for i in range(3,N):
  ans+=(3**i-3*(2**i)+3)
#N桁の753数を考える
ls=[7,5,3]
for i in range(1,N):
  ls_3=[10*s+3 for s in ls]
  ls_5=[10*s+5 for s in ls]
  ls_7=[10*s+7 for s in ls]
  ls=ls_3+ls_5+ls_7
 #753数か？
def judge(n):
  if n>X:
    return 0
  else:
    if(('3' in str(n))and('5' in str(n))and('7' in str(n))):
      return 1
    else:
      return 0
for t in ls:
  ans+=judge(t)
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
ls = ["3", "5", "7"]
cnt = 0
for i in range(3, len(str(n)) + 1):
    for j in itertools.product(ls, repeat=i):
        if "3" in j and "5" in j and "7" in j:
            t = ""
            for k in j:
                t += k
            if 1 <= int(t) <= n:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools

def main():
    N = int(input())

    num = ['3','5','7']
    num_list = set()

    for a in num:
        for b in num:
            for c in num:
                num_list.add(a+b+c)
                for d in num:
                    num_list.add(a+b+c+d)
                    for e in num:
                        num_list.add(a+b+c+d+e)
                        for f in num:
                            num_list.add(a+b+c+d+e+f)
                            for g in num:
                                num_list.add(a+b+c+d+e+f+g)
                                for h in num:
                                    num_list.add(a+b+c+d+e+f+g+h)
                                    for i in num:
                                        num_list.add(a+b+c+d+e+f+g+h+i)

    cnt = 0
    for i in num_list:
        if i.count("3") >= 1 and i.count("5") >= 1 and i.count("7") >= 1:
            if int(i) <= N:
                cnt += 1

    print(cnt)
    

main()

Submission status: Accepted

Solution code:
n = int(input())

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

print(dfs("0"))

Submission status: Accepted

Solution code:
n=int(input())
def f(x):
	if int(x)>n:return 0
	else:return all(d in x for d in"357")+f(x+"3")+f(x+"5")+f(x+"7")
print(f("0"))

Submission status: Accepted

Solution code:
n=int(input())
def dfs(x):
	if int(x)>n:
		return 0
	else:
		return all(d in x for d in "357")+dfs(x+"3")+dfs(x+"5")+dfs(x+"7")
print(dfs("0"))

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
##############################

N = int(input())

def dfs(next_value, value, count_flag, count):
    value += next_value
    int_value = int(value)

#    print(int_value)

    if int_value > N:
        return count

    if int_value >= 357:
        if count_flag == False:
            if len(set(list(value))) == 3:
                count_flag = True

        if count_flag:
            count += 1

    count = dfs('3', value, count_flag, count)
    count = dfs('5', value, count_flag, count)
    count = dfs('7', value, count_flag, count)

    return count


count = 0
value = ''

count = dfs('3', '', False, count)
count = dfs('5', '', False, count)
count = dfs('7', '', False, count)

print(count)

Submission status: Accepted

Solution code:
import itertools
n = input()
length = len(n)
n = int(n)

num_list = []
for i in range(length,2,-1):
    l = list(itertools.product(['3','5','7'],repeat = i))
    l = [int(''.join(i)) for i in l if len(set(i)) == 3 ]
    num_list.extend(l)
    
num_list = [i for i in num_list if i <= n]

print(len(num_list))

Submission status: Accepted

Solution code:

N = int(input())

ketalis = list(str(N))
ketalis.reverse()

dp = []

for i in range(10):

    a = []

    for i2 in range(2):
        b = []

        for i3 in range(2):
            c = []

            for i4 in range(2):
                d = []

                for i5 in range(2):
                    e = []

                    for i6 in range(2):

                        e.append(-1)

                    d.append(e)

                c.append(d)

            b.append(c)
            
        a.append(b)

    dp.append(a)

dp[0][0][0][0][0][0] = 1

#print (dp[4][0][0][0][0][0])


for i in range(10):

    if i == 0:
        continue;

    keta = 10 - i

    nowketa = 0

    if len(ketalis) >= keta:

        nowketa = int(ketalis[keta-1])


    for sf in range(2):

        for ff in range(2):

            for tf in range(2):

                for mnf in range(2):

                    for mxf in range(2):

                        for x in [0,3,5,7]:

                            if dp[i-1][sf][ff][tf][mnf][mxf] == -1:
                                continue;


                            nsf = sf
                            nff = ff
                            ntf = tf
                            nmnf = mnf
                            nmxf = mxf


                            if x == 0 and mxf == 1: #最上位ビットが出た後だと0はたせない
                                continue;

                            if x != 0 and mxf == 0: #最上位ビットが出た時の処理
                                nmxf = 1

                            if mnf == 0:

                                if x > nowketa:
                                    continue;

                                if x < nowketa:
                                    nmnf = 1

                            if x == 7:
                                nsf = 1
                            if x == 5:
                                nff = 1
                            if x == 3:
                                ntf = 1

                            if dp[i][nsf][nff][ntf][nmnf][nmxf] == -1:
                                dp[i][nsf][nff][ntf][nmnf][nmxf] = 0

                            dp[i][nsf][nff][ntf][nmnf][nmxf] += dp[i-1][sf][ff][tf][mnf][mxf]

print (max(0,max(0,dp[-1][1][1][1][0][1]) + max(0,dp[-1][1][1][1][1][1])))

Submission status: Accepted

Solution code:
import itertools
s = input()
n = int(s)
l = len(s)
lst = []
for i in range(3, l + 1):
    lst += list(itertools.product([3, 5, 7], repeat=i))
lst = [x for x in lst if 3 in x]
lst = [x for x in lst if 5 in x]
lst = [x for x in lst if 7 in x]
lst = [int("".join(map(str, x))) for x in lst]
lst = [x for x in lst if x <= n]
print(len(lst))

Submission status: Accepted

Solution code:
a = []

def h(t):
  return 3 in t and 5 in t and 7 in t

def comb(t):
  l = 0
  for i in t:
    l += i
    l = l * 10
  return l // 10

import itertools

for i in range(10):
  a += [comb(x) for x in list(itertools.product([3, 5, 7], repeat=i)) if h(x)]

n = int(input())

t = 0

for i in a:
  if i <= n:
    t += 1

print(t)

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()

def dfs(s):
    if int(s)>N:
        return 0
    else:
        if all(s.count(c)>=1 for c in ['3','5','7']):
            ret = 1
        else:
            ret = 0
        for x in ['3','5','7']:
            ret += dfs(s+x)
        return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    if N < 357: return 0

    cur = ["3", "5", "7"]
    count = 0
    while cur:
        temp = []
        for s in cur:
            if "3" in s and "5" in s and "7" in s:
                count += 1
            for c in "357":
                if int(c+s) <= N:
                    temp.append(c+s)
        cur = temp
    return count

if __name__ == '__main__':
    print(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 '357') else 0
    for c in '357':
        ret += dfs(s+c)
    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
n = int(input())


def dfs(x):
  if int(x) > n:
    return 0
  ret = 0
  if all(x.count(c) >= 1 for c in '753'):
    ret += 1
  for c in '753':
    ret += dfs(x + 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:
from itertools import product
n = int(input())
cnt = 0
for i in range(3,10):
    for m in product(["3","5","7"],repeat = i):
        if "3" in m and "5" in m and "7" in m and int("".join(m))<=n:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(num, cnt):
  if num > n: return 0
  str_num = str(num)
  ret = 0
  if ('7' in str_num) and ('5' in str_num) and ('3' in str_num):
    ret = 1
  
  ret += dfs(int(str_num + '7'), cnt)
  ret += dfs(int(str_num + '5'), cnt)
  ret += dfs(int(str_num + '3'), cnt)
  return ret
ans = dfs(0,0)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
count = 0

def solve(s):
    global count
    if int(s) > n:
        return

    if all(s.count(c) > 0 for c in '753'):
        count += 1

    for c in '753':
        solve(s + c)

solve('0')
print(count)

Submission status: Accepted

Solution code:
N = int(input())

def shichigosan(x):
  if x == "":
    r = 0
    r += shichigosan(x+"3")
    r += shichigosan(x+"5")
    r += shichigosan(x+"7")
    return r
  else:
    if int(x) > N:
      return 0
    else:
      r = 0
      if '3' in x and '5' in x and '7' in x:
        r = 1      
      r += shichigosan(x+"3")
      r += shichigosan(x+"5")
      r += shichigosan(x+"7")
      return r
        
print(shichigosan(""))

Submission status: Accepted

Solution code:
def make_good_753(a,digit):
    ans_list = []
    str_list = ["7","5","3"]
    for i in range(digit):
        ans_list.append(a%3)
        a //= 3
    ans_list.reverse()
    ans_list = [ str_list[i] for i in ans_list]
    if set(ans_list) == {'7', '3', '5'}:
        return int("".join(ans_list))
    else:
        return None

candidate_list = []
n = int(input())
for i in range(3,10):
    for j in range(3**i):
        candidate = make_good_753(j,i)
        if candidate != None:
            if candidate <= n:
                candidate_list.append(candidate)
print(len(candidate_list))

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

N = int(input())

def is753(s):
    return all(s.count(c) > 0 for c in "753")

a = []
def f(s):
    if int(s) > N:
        return
    if is753(s):
        a.append(s)
    for c in "753":
        f(str(int(s+c)))
f("0")
#print(a)

ans = 0
for s in a:
    ans += 1 if is753(s) else 0

print(ans)

Submission status: Accepted

Solution code:
import itertools


def solve():
    n = int(input())
    c = 0
    for i in range(3, len(str(n)) + 1):
        for v in itertools.product(["3", "5", "7"], repeat=i):
            num = int("".join(v))
            if is_good(num) and num <= n:
                c += 1
    return c


def is_good(i):
    return set(str(i)) == {"3", "5", "7"}


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
import math
n_in = int(input())


def sgs(n, a, s, s_temp):
    if a == math.ceil(math.log(n, 10)):
        c = 0
        for i in s:
            i_listed = list(map(int, list(str(i))))
            if 3 in i_listed and 5 in i_listed and 7 in i_listed:
                if i <= n:
                    c += 1
    else:
        a += 1
        temp = []
        for i in s_temp:
            s.append(10 * i + 3)
            s.append(10 * i + 5)
            s.append(10 * i + 7)
            temp.append(10 * i + 3)
            temp.append(10 * i + 5)
            temp.append(10 * i + 7)
        s_temp = temp
        c = sgs(n, a, s, s_temp)
    return c


ans = sgs(n_in, -1, [3, 5, 7], [3, 5, 7])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

ans = 0

for i in range(4**len(str(n))):
    cnt = Base_10_to_n(i, 4)

    if cnt.count("0") != 0 or (cnt.count("1") == 0 or cnt.count("2") == 0 or cnt.count("3") == 0):
        continue

    temp = []
    for j in range(len(cnt)):
        if cnt[j] == "1":
            temp.append("3")
        elif cnt[j] == "2":
            temp.append("5")
        elif cnt[j] == "3":
            temp.append("7")
    num = int("".join(temp))

    if num <= n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=str(input())
ans=0
for i in range(3,len(n)+1):
    for j in itertools.product([3,5,7], repeat=i):
        if (3 not in j) or (5 not in j) or (7 not in j):
            continue
        a=''.join(list(map(str,j)))
        if int(a)<=int(n):
            ans+=1
print(ans)