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 next_357(num_arr,i=-1):
    if len(num_arr) < -i:
        num_arr.insert(0,3)
        return num_arr
    if num_arr[i] == 3:
        num_arr[i] = 5
        return num_arr
    elif num_arr[i] == 5:
        num_arr[i] = 7
        return num_arr
    elif num_arr[i] == 7:
        num_arr[i] = 3
        i -= 1
        return next_357(num_arr,i)
ans = 1
a357 = [3,5,7]
while True:
    if N < 357:
        ans = 0
        break
    elif N == 357:
        break
    else:
        a357 = next_357(a357)
        if int("".join(map(str, a357))) <= N:
            if a357.count(3) >= 1 and a357.count(5) >= 1 and a357.count(7) >= 1:
                ans += 1
        else:
            break
print(ans)

Submission status: Accepted

Solution code:

n = int(input())

if n < 357:
    print(0)
    exit()

def dfs(start):
    if int(start) > n:
        return 0
    if not ("3" in start and "5" in start and "7" in start):
        count=0
    else:
        count=1
    count += dfs(start + "3")
    count += dfs(start + "5")
    count += dfs(start + "7")
    return count
print(dfs("3")+dfs("5")+dfs("7"))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(200000)
n = int(input())

if n < 357:
    print(0)
    exit()

def dfs(start):
    if int(start) > n:
        return 0
    if not ("3" in start and "5" in start and "7" in start):
        count=0
    else:
        count=1
    count += dfs(start + "3")
    count += dfs(start + "5")
    count += dfs(start + "7")
    return count
print(dfs("3")+dfs("5")+dfs("7"))

Submission status: Accepted

Solution code:
import itertools

N=input()

ans=0
for i in range(3,len(N)+1):
    for j in itertools.product('357', repeat=i):
        s=''.join(j)
        if int(s)<=int(N) and s.count('3')>=1 and s.count('5')>=1 and s.count('7')>=1:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
N = input()
# print(N)
d = len(N)

T = [0, 3, 5, 7]
A = []
for i in range(4**d):
    for j in range(d):
        n = i
        c = 0
        a = 0
        for k in range(j + 1):
            a += T[n % 4] * 10**c
            n //= 4
            c += 1
    A.append(a)

def is753(n):
    if n == 0:
        return False
    n_str = str(n)
    has3 = False
    has5 = False
    has7 = False
    for s in n_str:
        if s == '0':
            return False
        elif s == '3':
            has3 = True
        elif s == '5':
            has5 = True
        elif s == '7':
            has7 = True
    return has3 and has5 and has7

ans = []
ans = [x for x in A if x <= int(N) and is753(x)]
# print(A)
# print(ans)
print(len(ans))

Submission status: Accepted

Solution code:
import itertools

N = int(input())

se = set([0])
for _ in range(10):
  se |= set(10*x+y for x,y in itertools.product(se,[7,5,3]))
  
se = set(str(x) for x in se if 1 <= x <= N)
se = set(x for x in se if set(x) == set('753'))
answer = len(se)
print(answer)

Submission status: Accepted

Solution code:
S = input()

def solve(s):
	if s and int(s) > int(S):
		return 0
	count = 0
	if set(s) == set("753"):
		#print(s)
		count = 1
	for c in "753":
		count += solve(s + c)
	return count

print(solve(""))

Submission status: Accepted

Solution code:
S = input()

def solve(s, n=0, tight=True, value=""):
	if n == len(s):
		while value and value[0] == "0":
			value = value[1:]
		if set("753") == set(value):
			#print(value)
			return 1
		return 0
	hi = int(s[n]) if tight else 9
	c = 0
	for i in range(hi + 1):
		if i in [7, 5, 3, 0]:
			c += solve(s, n + 1, tight and not(i < hi), value + str(i))
	return c

print(solve(S))

Submission status: Accepted

Solution code:
N = int(input())
M = len(str(N))
res = [0]
def dfs(x):
    # 長さがMになったら終了
    if len(x) > M:
        return
    if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0 and int(x) <= N:
        res[0] += 1
    dfs(x + '3')
    dfs(x + '5')
    dfs(x + '7')
    return

dfs('3')
dfs('5')
dfs('7')
print(res[0])

Submission status: Accepted

Solution code:
N = int(input())
M = len(str(N))

def nsin(X,n):
    if(int(X/n)):
        return nsin(int(X/n),n)+str(X%n)
    return str(X%n)

res = 0
for m in range(3,M+1):
    for i in range(3 ** m):
        tri = nsin(i, 3).zfill(m)
        nl = []
        if tri.count('0') > 0 and tri.count('1') > 0 and tri.count('2') > 0:
            for j in range(m):
                if tri[j] == '0':
                    nl.append('3')
                elif tri[j] == '1':
                    nl.append('5')
                else:
                    nl.append('7')
            x = ''.join(nl)
            if int(x) <= N:
                res += 1

print(res)

Submission status: Accepted

Solution code:
n=int(input())
def dfs(m):
  if m>n:return 0
  a=all(str(m).count(i)>0for i in"753")+0
  for i in [7,5,3]:a+=dfs(m*10+i)
  return a
print(dfs(0))

Submission status: Accepted

Solution code:
N = int(input())

def saiki(i,ans):
    if i>N:
        return ans
    else:
        s = str(i)
        if ("7" in s) and ("5" in s) and ("3" in s):
            ans += 1
        ans = saiki(i*10+3,ans)
        ans = saiki(i*10+5,ans)
        ans = saiki(i*10+7,ans)
        return ans
    
print(saiki(0,0))

Submission status: Accepted

Solution code:
N = int(input())

num_len = len(str(N))

lis = []

def dfs(cur, number, count):
    if '3' in number and '5' in number and '7' in number:
        if int(number) <= N:
            lis.append(number)
    if num_len == cur:
        return

    ret1 = dfs(cur + 1, number + '3', count)
    ret2 = dfs(cur + 1, number + '5', count)
    ret3 = dfs(cur + 1, number + '7', count)
    
    return lis


print(len(dfs(0, '', count=0)))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# 10 -> n
def ten2n(a,n):
  x=a//n
  y=a%n
  if x:
    return ten2n(x,n)+str(y)
  return str(y)

def main():
  n=I()

  l=[]
  for i in range(pow(4,9)):
    l.append(ten2n(i,4).replace('3','7').replace('2','5').replace('1','3'))

  cnt=0
  for x in l:
    if int(x)<=n:
      if '3' in x and '5' in x and '7' in x and '0' not in x:
        cnt+=1
    else:
      break

  return cnt

print(main())

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
#文字列sで始まる七五三数の個数
    if int(s) > N:
        return 0
    #s自体が七五三数なら+1
    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 itertools
n = input()
dp = [[[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]for l in range(len(n))]
#dp[i桁目][nより小さいかどうか][3がある][5がある][7がある]

for i in range(len(n)):
    dp[i][0][0][0][0] = 1

for j in range(10):
    if int(n[0]) >= j and j in [3, 5, 7]:
        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1

for i, j, k, l, m in itertools.product(range(len(n)-1), range(2), range(2), range(2), range(10)):
    if m in [3, 5, 7]:
        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]
        if m <= int(n[i+1]):
            dp[i + 1][m == int(n[i+1])][j or m == 3][k or m == 5][l or m == 7] += dp[i][1][j][k][l]

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

Submission status: Accepted

Solution code:
import itertools
n = input()
dp = [[[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]for l in range(len(n))]
#dp[i桁目][nより小さいかどうか][3がある][5がある][7がある]

for i in range(len(n)):
    dp[i][0][0][0][0] = 1

for j in range(10):
    if int(n[0]) >= j:
        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1
dp[0][1][0][0][0] = 0

for i, j, k, l, m in itertools.product(range(len(n)-1), range(2), range(2), range(2), range(10)):
    if m in [3, 5, 7]:
        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]
        if m <= int(n[i+1]):
            dp[i + 1][m == int(n[i+1])][j or m == 3][k or m == 5][l or m == 7] += dp[i][1][j][k][l]

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

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = input()
digits = len(N)

#DP[0~N][tight][a7ed][a5ed][a3ed]
#最初の添字にNまで許しているのは、全部を選んで「N+1個目を選ぶ」というループで、正誤判定を行えばいいという考えから
#DP[N]~は全て初期から入れてしまうことで、tightの場合に桁の数字を読み込もうとしてindex errorが起きるのを防ぐ
DP = [[[[[-1] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(digits+1)]

#正誤判定。これら以外の場合は、「残り必要7,5,3に対して残り桁数が足りない」判定でまかなえるので初期化の必要なし
#いや、残りの2つも最後の3**(digits-digit)でいける... とはいえ計算量削減に繋がりそうなので放っておく
DP[digits][0][1][1][1] = 1
DP[digits][1][1][1][1] = 1

#残りdigitが2以下で7,5,3が一つも出てなければ明らかに無理
#あとは残りdigitが1で2つ残ってるときも
DP[digits-1][0][0][0][0] = 0
DP[digits-1][1][0][0][0] = 0
DP[digits-1][0][1][0][0] = 0
DP[digits-1][0][0][1][0] = 0
DP[digits-1][0][0][0][1] = 0
DP[digits-1][1][1][0][0] = 0
DP[digits-1][1][0][1][0] = 0
DP[digits-1][1][0][0][1] = 0
DP[digits-2][0][0][0][0] = 0
DP[digits-2][1][0][0][0] = 0

#いけるパターン
DP[digits-1][0][1][1][0] = 1
DP[digits-1][0][1][0][1] = 1
DP[digits-1][0][0][1][1] = 1

import sys
sys.setrecursionlimit(10**9)

#(既に探索した桁数、未満フラグ、already7ed, same, same)
#digits-digitで「残り桁数」が見られる
def solve(digit, tight, a7ed, a5ed, a3ed):
  global digits
  #-1じゃなければ~()が値を持つのでifに入り、そのままDPの値を返す。
  #-1(111111..)なら0になるのでelseに入って値を求める
  if ~(DP[digit][tight][a7ed][a5ed][a3ed]):
#    print('already visited',digit, tight, a7ed, a5ed, a3ed,'DPは',DP[digit][tight][a7ed][a5ed][a3ed])
    return DP[digit][tight][a7ed][a5ed][a3ed]
  else: #まだ値が入っていない場合
    if digits-digit < 3-a7ed-a5ed-a3ed:
      DP[digit][tight][a7ed][a5ed][a3ed] = 0
      return 0
    #残り桁数よりも、「7,5,3のうち足りないものの数」が多ければ、753数は無し
    if tight:
#      print('tight',digit, tight, a7ed, a5ed, a3ed)
      target = int(N[digit])
#      print('target=',target)
      #まだ1つも数字を選んでいなければ、0を選ぶパターンがある
      tmp = 0 if a7ed|a5ed|a3ed else solve(digit+1,0,0,0,0)
      if target <= 2: tmp += 0
      elif target == 3: tmp += solve(digit+1, 1, a7ed, a5ed, a3ed | 1)
      elif target == 4: tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1)
      elif target == 5: tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1) + solve(digit+1, 1, a7ed, a5ed | 1, a3ed)
      elif target == 6: tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1) + solve(digit+1, 0, a7ed, a5ed | 1, a3ed)
      elif target == 7: tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1) + solve(digit+1, 0, a7ed, a5ed | 1, a3ed) + solve(digit+1, 1, a7ed | 1, a5ed, a3ed)
      else: #8,9の場合
        tmp += solve(digit+1, 0, a7ed, a5ed, a3ed | 1) + solve(digit+1, 0, a7ed, a5ed | 1, a3ed) + solve(digit+1, 0, a7ed | 1, a5ed, a3ed)
      DP[digit][tight][a7ed][a5ed][a3ed] = tmp
      return tmp
    else: #自由！
#      print('not tight',digit, tight, a7ed, a5ed, a3ed, '残り桁数は',digits-digit)
      if a7ed & a5ed & a3ed: #全て1なら
        tmp = 3**(digits-digit) #3^残り桁のパターンがある
        DP[digit][tight][a7ed][a5ed][a3ed] = tmp
        return tmp
      else:
        #一度0を選んだあと、tightではなくなっているが、その後も、まだ1つも数字を選んでいなければ、0を選ぶパターンはありえる
        tmp = 0 if a7ed|a5ed|a3ed else solve(digit+1,0,0,0,0)
        #次の桁は7,5,3のどれか
        tmp += solve(digit+1, 0, a7ed | 1, a5ed, a3ed) + solve(digit+1, 0, a7ed, a5ed | 1, a3ed) + solve(digit+1, 0, a7ed, a5ed, a3ed | 1)
        DP[digit][tight][a7ed][a5ed][a3ed] = tmp
        return tmp

print(solve(0,1,0,0,0))
#print(DP[2][0][0][0][0],DP[1][0][0][0][0], DP[1][0][1][0][0],DP[1][0][0][1][0],DP[1][0][0][0][1])

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
p = [0]
while p:
    k = p.pop()
    if k > N:
        continue
    if '7' in str(k) and '5' in str(k) and '3' in str(k):
        ans += 1
    p.extend([k*10+3, k*10+5, k*10+7])
print(ans)

Submission status: Accepted

Solution code:
N=input()
ans=0

def f(x):
    result=""
    while x>=1:
        result+=str(x%3)
        x=int(x/3)
    result=result[::-1]
    return(result)

for M in range(len(N)+1):
    for n in range(3**M-1):
        number=f(n).zfill(M)
        if number.count("0")==0 or number.count("1")==0 or number.count("2")==0:
            pass
        else:
            number753=""
            for k in range(len(number)):
                if number[k]=="0":
                    number753+="3"
                elif number[k]=="1":
                    number753+="5"
                else:
                    number753+="7"
            if int(number753)>int(N):
                pass
            else:
                ans+=1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dp = ["3"]
brk = False
for i in range(n):
    if brk == True:
        break
    for c in "357":
        if int(dp[i]+c)>n:
            brk = True
            break
        dp.append(dp[i]+c)
        
dp2 = ["5"]
brk = False
for i in range(n):
    if brk == True:
        break
    for c in "357":
        if int(dp2[i]+c)>n:
            brk = True
            break
        dp2.append(dp2[i]+c)

dp3 = ["7"]
brk = False
for i in range(n):
    if brk == True:
        break
    for c in "357":
        if int(dp3[i]+c)>n:
            brk = True
            break
        dp3.append(dp3[i]+c)

dp = dp+dp2+dp3
count = 0
for i in range(len(dp)):
    if all(dp[i].count(c) for c in "753"):
        count += 1
print(count)

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 '753') else 0
    for c in '753':
        ret += dfs(s + c, N)
    return ret

def main():
    N = int(input())
    print(dfs('0', N))

main()

Submission status: Accepted

Solution code:
# ABC114C - 755
def shichi_go_san(s="0"):
    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 += shichi_go_san(s + c)
    return ret


n = int(input())
print(shichi_go_san())

Submission status: Accepted

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

def ternary(t):
  t = list(map(int, list(t)))
  t = list(reversed(t))
  for i in range(len(t)):
    t[i] = t[i] + 1
    d = t[i] // 3
    t[i] = t[i] % 3
    
    if d <= 0:
      break
    else:
      if i == len(t)-1:
        t.append(0)
  return ''.join(map(str, list(reversed(t))))

def scg(t):
  t = t.replace('3', '0')
  t = t.replace('5', '1')
  t = t.replace('7', '2')
  
  t = ternary(t)
  
  t = t.replace('0', '3')
  t = t.replace('1', '5')
  t = t.replace('2', '7')
  
  return t

value = '357'
while n >= int(value):
  if '3' in value and '5' in value and '7' in value:
    ans += 1
  value = scg(value)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
num = ['3','5','7']
for i in range(len(str(N))-1):
    num2 = []
    for n in num:
        num2.append(n+'3')
        num2.append(n+'5')
        num2.append(n+'7')
        num2.append(n)
    num = num2
cnt = 0
num = set(num)
for n in num:
    if '3' in n and '5' in n and '7' in n:
        if int(n) <= N:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
ans = 0
for i in range(1, len(str(n))+1):
    for x in product('357', repeat=i):
        flag = True
        for p in '357':
            if not p in x:
                flag = False
                break
        if flag:
            if int("".join(x)) <= n:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

stgsn = []

def make753(nowstr,three,five,seven,isEnd):
    #print(nowstr,three,five,seven,isEnd,len(nowstr))
    if len(nowstr) > len(str(N)):
        #print("isEnd")
        isEnd = True
        return 0
    if three and five and seven and (int(nowstr) <= N):
        stgsn.append(nowstr)

    #末尾に追加
    if not isEnd:
        make753(nowstr+"3",True,five,seven,isEnd)
        make753(nowstr+"5",three,True,seven,isEnd)
        make753(nowstr+"7",three,five,True,isEnd)

make753("",False,False,False,False)

print(len(stgsn))

Submission status: Accepted

Solution code:
N = int(input())
all = []
nums = [3,5,7]
for i in range(8):
    tmp = []
    for n in nums:
        tmp.append(n*10+3)
        tmp.append(n*10+5)
        tmp.append(n*10+7)
    all += nums
    nums = tmp
all += nums
all.sort()
ans = 0
for a in all:
    if a > N:
        break
    if '3' in str(a) and '5' in str(a) and '7' in str(a):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

counter = 0
def main():
    N = II()
    def dp(number, has_seven, has_five, has_three):
        global counter
        if int(number+'7') <= N:
            if has_five and has_three:
                counter += 1
            dp(number+'7', True, has_five, has_three)
        if int(number+'5') <= N:
            if has_seven and has_three:
                counter += 1
            dp(number+'5', has_seven, True, has_three)
        if int(number+'3') <= N:
            if has_seven and has_five:
                counter += 1
            dp(number+'3', has_seven, has_five, True)
    dp('',False,False,False)
    print(counter)

main()

Submission status: Accepted

Solution code:
X=int(input())
def dp(N,seq):
    if N!=0:
        if min(seq.count("3"),seq.count("5"),seq.count("7"))!=0:
            if int(seq)<=X:
                p.append(seq)
    if N<10:
        dp(N+1,seq+"3")
        dp(N+1,seq+"5")
        dp(N+1,seq+"7")
p=[]
dp(0,"")
print(len(p))

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

    # そのnode配下で条件を満たす値のパターン数を返す
    def rec(svalue, maximum):
        add = 0
        if svalue != "":
            if int(svalue) <= maximum: 
                if ('7' in svalue and '5' in svalue and '3' in svalue):
                    add = 1
            else:
                return 0

        
        sevens = rec(svalue + '7', maximum)
        fives = rec(svalue + '5', maximum)
        threes = rec(svalue + '3', maximum)
        return sevens + fives + threes + add
    
    print(rec("", N))
        

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
# 2019/06/08
# AtCoder Beginner Contest 114 - C

def makeval(in_sn):
    div = int(in_sn / 4)
    rem = in_sn % 4
    if div == 0:
        if rem == 0:
            return "X"
        elif rem == 1:
            return "3"
        elif rem == 2:
            return "5"
        elif rem == 3:
            return "7"
    else:
        ret = makeval(div)
        if rem == 0:
            return ret + "3"
        elif rem == 1:
            return ret + "5"
        elif rem == 2:
            return ret + "7"
        elif rem == 3:
            return "X"
# Input
n = int(input())

wval = 1
cnt = 0
idx = 1

while(wval <= n):
    wstr = makeval(idx)
    if ("X" in wstr) == False:
        if ("3" in wstr) == True and ("5" in wstr) == True and ("7" in wstr) == True :
            wval = int(wstr)
            cnt += 1
    
    idx += 1

cnt -= 1

# Output
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())

ans = [0]

def calc(s):
    if int(s) <= N:
        if "3" in s and "5" in s and "7" in s:
            ans[0] += 1
        for e in ["3", "5", "7"]:
            calc(s + e)

for e in ["3", "5", "7"]:
    calc(e)

print(ans[0])

Submission status: Accepted

Solution code:
def judge(s):
    ans = 0
    add_3 = s * 10 + 3
    if add_3 <= N:
        str_num = str(add_3)
        if str_num.count("3") and str_num.count("5") and str_num.count("7"):
            ans += 1
        ans += judge(add_3)
    add_5 = s * 10 + 5
    if add_5 <= N:
        str_num = str(add_5)
        if str_num.count("3") and str_num.count("5") and str_num.count("7"):
            ans += 1
        ans += judge(add_5)
    add_7 = s * 10 + 7
    if add_7 <= N:
        str_num = str(add_7)
        if str_num.count("3") and str_num.count("5") and str_num.count("7"):
            ans += 1
        ans += judge(add_7)
    return ans


N = int(input())

print(judge(0))

Submission status: Accepted

Solution code:
arr=[3,5,7]

global res
res = 0
ma = int(input())

def gen(num = 0):
    global res
    # print(num)
    if ma < num:
        return
    else:
        st = str(num)
        if st.count('3') and st.count('5') and st.count('7'):
            res += 1

    for i in arr:
        if num == 0:
            gen(num+i)
        else:
            gen(10*num + i)

gen()
print(res)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
from collections import deque


def gen753number(max_value):
    numbers = '357'
    que = deque([l for l in numbers])

    while True:
        while len(que):
            pre = que.popleft()
            if int(pre) > max_value:
                break
            if all([i in pre for i in numbers]):
                yield pre
            for n in numbers:
                que.append(pre + n)
        break


n = int(input())
print(len(list(gen753number(n))))

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')) #

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
def sft(s):
    global ans
    if int(s) >= N:
        return ans
    for x in '357':
        if int(s+x) > N:
            break
        sft(s+x)
        if '3' in s+x and '5' in s+x and '7' in s+x:
            #print(s+x)
            ans += 1
    return ans
print(sft('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) for c in "753") 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(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:
N = int(input())
ans = 0
for i in range(1, (4 ** 9)+1):
    tmp = ""
    now = i
        
    while now != 0:
        if now % 4 == 0:
            tmp += "0"
        elif now % 4 == 1:
            tmp += "3"
        elif now % 4 == 2:
            tmp += "5"
        else:
            tmp += "7"

        now //= 4

    
    tmp = str(int(tmp[::-1]))
    if "3" in tmp and "5" in tmp and "7" in tmp:
        tmp = int(tmp)
        if tmp <= N and "0" not in str(tmp):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n=input()
deg=len(n)
n=int(n)
d=['3','5','7']
d1=['3','5']
d2=['5','7']
d3=['3','7']
cnt=0
if deg<2:
     print(0)
else:
     for i in range(3,deg+1):
          d_=list(product(d,repeat=i))
          d1_=list(product(d1,repeat=i))
          d2_=list(product(d2,repeat=i))
          d3_=list(product(d3,repeat=i))
          d_=[x for x in d_ if x not in d1_]
          d_=[x for x in d_ if x not in d2_]
          d_=[x for x in d_ if x not in d3_]
          for x in d_:
               x=list(x)
               a=int(''.join(x))
               if a<=n:
                    cnt+=1
               else:
                    break
     print(cnt)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()

  cnt=0
  for j in range(-1,3):
    for b in range(-1,3):
      for c in range(-1,3):
        for d in range(-1,3):
          for e in range(-1,3):
            for f in range(-1,3):
              for g in range(-1,3):
                for h in range(-1,3):
                  for i in range(-1,3):
                    a=0

                    if i==0:
                      a+=3
                    elif i==1:
                      a+=5
                    elif i==2:
                      a+=7

                    if h==0:
                      a+=30
                    elif h==1:
                      a+=50
                    elif h==2:
                      a+=70

                    if g==0:
                      a+=300
                    elif g==1:
                      a+=500
                    elif g==2:
                      a+=700

                    if f==0:
                      a+=3000
                    elif f==1:
                      a+=5000
                    elif f==2:
                      a+=7000

                    if e==0:
                      a+=30000
                    elif e==1:
                      a+=50000
                    elif e==2:
                      a+=70000

                    if d==0:
                      a+=300000
                    elif d==1:
                      a+=500000
                    elif d==2:
                      a+=700000

                    if c==0:
                      a+=3000000
                    elif c==1:
                      a+=5000000
                    elif c==2:
                      a+=7000000

                    if b==0:
                      a+=30000000
                    elif b==1:
                      a+=50000000
                    elif b==2:
                      a+=70000000

                    if j==0:
                      a+=300000000
                    elif j==1:
                      a+=500000000
                    elif j==2:
                      a+=700000000

                    if a>n:
                      return cnt
                    else:
                      x=list(set(str(a)))
                      if x.count('0')>0:
                        continue
                      if len(x)==3:
                        cnt+=1
  
  return cnt

print(main())

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

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

    res = []
    def rec(n, i, k):
        if k == 1:
            res.append(n+i*(10**(k-1)))
            return
        rec(n+i*(10**(k-1)), 3, k-1)
        rec(n+i*(10**(k-1)), 5, k-1)
        rec(n+i*(10**(k-1)), 7, k-1)

    for l in range(3, len(str(N))+1):
        rec(0, 3, l)
        rec(0, 5, l)
        rec(0, 7, l)

    cnt = 0
    for on in res:
        if on > N:
            break
        found = True
        seven = False
        five = False
        three = False
        n = on
        for j in range(len(str(on))):
            a = int(n % 10)
            n /= 10
            if a != 7 and a != 5 and a != 3:
                found = False
            if a == 7:
                seven = True
            if a == 5:
                five = True
            if a == 3:
                three = True
        if found and seven and five and three:
            cnt += 1
    print(cnt)

main()

Submission status: Accepted

Solution code:
import itertools

N = int(input())

number = [7, 5, 3]

ans = 0
for i in range(10):
    for conv in itertools.product(number, repeat=i+1):
        
        tmp = 0
        for j in range(len(conv)):
            tmp += conv[j] * 10 ** (len(conv) - j - 1)
            
        
        if ((3 in conv) and (5 in conv) and (7 in conv)) and tmp <= N:
            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 # 数値に753が入っているか？
  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())
ans = 0
S = []
for i in range(10):
    S += list(product("357",repeat=i))
for s in S:
  if len(set(s)) > 2 and int("".join(s)) <= n:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=input()
ans=0
355
lst=[]
def generate(n,x,count,lst):
    if 0<count<len(n)+1:
        if int(x)<=int(n):
            lst.append(x)
    elif count==0:
        pass
    else:
        return lst
    generate(n,x+'3',count+1,lst)
    generate(n,x+'5',count+1,lst)
    generate(n,x+'7',count+1,lst)
        
x=''
generate(n,x,0,lst)
ans=0
for i in lst:
    san=nana=go=False
    if '3' in i:
        san=True
    if '5' in i:
        go=True
    if '7' in i:
        nana=True
    if san==nana==go==True:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
N = int(input())
l = deque()

def solve(s, l):
    if len(s):
        if int(s) > N:
            l.pop()
            return

    for a in '357':
        ns = s + a
        l.append(ns)
        solve(ns, l)
    return l

solve('', l)
ans = 0
for e in l:
    c = Counter(e)
    flg = True
    for n in '357':
        if c[n] == 0:
            flg = False
            break
    if flg:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

cnt = 0
def func(cur):
  global cnt
  if cur>N: return
  if set(str(cur)) == {'3', '5', '7'}: cnt += 1
  func(cur*10 + 3)
  func(cur*10 + 5)
  func(cur*10 + 7)

func(0)
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
def dfs(num ,depth, three,five,seven):
    global ans
    if depth == 0:
        if three and five and seven and num <= n:
            ans += 1
    else:
        dfs(10*num+3, depth-1, True, five, seven)
        dfs(10*num+5, depth-1, three, True, seven)
        dfs(10*num+7, depth-1, three, five, True)
for i in range(len(str(n))):
    dfs(0,i+1,False,False,False)
print(ans)