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: Time Limit Exceeded

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

for i in range(n):
    number = i+1
    three = 0
    five = 0
    seven = 0
    other = 0
    for j in range(len(str(number))):
        w = int(str(number)[j])
        if w == 3:
            three += 1
        elif w == 5:
            five += 1
        elif w == 7:
            seven += 1
        else:
            other += 1
    if three > 0 and five > 0 and seven > 0 and other == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def judge753(n):
    a=list(str(n))
    if str(n).replace('3','').replace('5','').replace('7','')=='' and '3' in a and '5' in a and '7' in a:
        return 1
    else:
        return 0
n=int(input())
count=0
for i in range(357,n+1):
    count+=judge753(i)
print(count)

Submission status: Time Limit Exceeded

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

N = int(input().strip())

def is753(n):
  targets = ['7','5','3']
  has7 = False
  has5 = False
  has3 = False
  """
  十進法で表記したとき、数字 7, 5, 3 がそれぞれ 1 回以上現れ、これら以外の数字は現れない。
  """
  nums = str(n)
  for i in nums:
    if i not in targets:
      return False
    else:
      if i == '7':
        has7 = True
      elif i == '5':
        has5 = True
      elif i == '3':
        has3 = True
  return has7 and has5 and has3

nums = range(1, N+1)
ans = list(filter(is753, nums))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = input()
ans = 0

def check(number):
    three = 0
    five = 0
    seven = 0
    for i in range(len(number)):
        if number[i:i+1] == '3':
            three += 1
        elif number[i:i+1] == '5':
            five += 1
        elif number[i:i+1] == '7':
            seven += 1
        else:
            return False
    if three >= 1 and five >= 1 and seven >= 1:
        return True
    else:
        return False

for i in range(int(N)+1):
    if check(str(i)) == True:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n + 1):
    if "3" in str(i) and "5" in str(i) and "7" in str(i):
        flag = True
        for j in str(i):
            if j != '3' and j != '5' and j != '7':
                flag = False
                break
        if flag:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

n_753 = 0

for i in range(1, N+1):
    digit = str(i)
    for j in '0124689':
        if j in digit:
            break
    else:
        if '7' in digit and '5' in digit and '3' in digit:
            n_753 += 1

print(n_753)

Submission status: Time Limit Exceeded

Solution code:
def is_753(s) :
	if (s.find("0") > -1) :
		return False
	elif (s.find("1") > -1) :
		return False
	elif (s.find("2") > -1) :
		return False
	elif (s.find("4") > -1) :
		return False
	elif (s.find("6") > -1) :
		return False
	elif (s.find("8") > -1) :
		return False
	elif (s.find("9") > -1) :
		return False
	
	if (s.find("7") > -1 and s.find("5") > -1 and s.find("3") > -1) :
		return True
	
	return False

N = int(input())
count = 0
# index = 0

for i in range(N+1) :
	s = str(i)
	if (is_753(s)) :
		count += 1

print(count)

Submission status: Accepted

Solution code:
N=int(input())
L=[3, 5, 7]
 
def dfs(s):
    if s>N:
        return False
 
    str_s = str(s)
    return sum(dfs(s*10 + i) for i in L) + ("7" in str_s and "5" in str_s and "3" in str_s)
 
 
print(dfs(0))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
list_N = [["3", "5", "7"]]

for i in range(2, 10):
    d = []
    for a in list_N[-1]:
        for b in ["3", "5", "7"]:
            k = b + a
            if n >= int(k) and "3" in k and "5" in k and "7" in k:
                ans += 1
            d.append(k)
    list_N.append(d)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())


def dfs(current, judge, count):
    if current > N:
        return
    if judge == 0b111:
        count.append(1)

    dfs(current * 10 + 7, judge | 0b100, count)
    dfs(current * 10 + 5, judge | 0b010, count)
    dfs(current * 10 + 3, judge | 0b001, count)


cnt = []
dfs(0, 0, cnt)
print(sum(cnt))

Submission status: Accepted

Solution code:
from itertools import product

n=int(input())
if n<357:
  print(0)
  exit()
ans=0
for i in range(3,len(str(n))):
  ans+=3**i-3*(2**i)+3

for i in product(['3','5','7'],repeat=len(str(n))):
  if '3' in i and '5' in i and '7' in i:
    if int(int(''.join(i)))<=n:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

cand = []
def rec(n):
  if n > 10**9:
    return
  cand.append(n)
  rec(int(str(n) + "3"))
  rec(int(str(n) + "5"))
  rec(int(str(n) + "7"))
rec(3)
rec(5)
rec(7)
ans = 0

def check(c):
  if "3" in str(c) and "5" in str(c) and "7" in str(c):
    return True
  else:
    return False

for c in cand:
  if c <= n and check(c):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
def readinput():
    n=int(input())
    return n

def main(n):
    stock=[]
    for _ in range(10):
        stock.append([])

    stock[0].append('')
    for m in range(1,10):
        for i in range(len(stock[m-1])):
            stock[m].append(stock[m-1][i]+'3')
            stock[m].append(stock[m-1][i]+'5')
            stock[m].append(stock[m-1][i]+'7')
    #print(stock)
    count=0
    for m in range(3,10):
        for i in range(len(stock[m])):
            if int(stock[m][i]) <= n and '3' in stock[m][i] and '5' in stock[m][i] and '7' in stock[m][i]:
                count+=1
                #print(stock[m][i])
    return count

S=[]
def dfs(s):
    global S
    if len(s)>10:
        return
    S.append(s)
    for c in '753':
        dfs(s+c)
    return

def main2(n):
    global S
    dfs('')
    count=0
    for s in S:
        if s!='' and int(s)>n:
            continue
        if '3' in s and '5' in s and '7' in s:
            count+=1
    return count

if __name__=='__main__':
    n=readinput()
    ans=main2(n)
    print(ans)

Submission status: Accepted

Solution code:
def readinput():
    n=int(input())
    return n

def main(n):
    stock=[]
    for _ in range(10):
        stock.append([])

    stock[0].append('')
    for m in range(1,10):
        for i in range(len(stock[m-1])):
            stock[m].append(stock[m-1][i]+'3')
            stock[m].append(stock[m-1][i]+'5')
            stock[m].append(stock[m-1][i]+'7')
    #print(stock)
    count=0
    for m in range(3,10):
        for i in range(len(stock[m])):
            if int(stock[m][i]) <= n and '3' in stock[m][i] and '5' in stock[m][i] and '7' in stock[m][i]:
                count+=1
                #print(stock[m][i])
    return count

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)

Submission status: Accepted

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


n = I()


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


print(dfs("0"))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)
N = input()
N_len = len(N)
'''
75333
'''


# t = []


def dfs(a, depth):
    if depth == N_len:
        if int(a) <= int(N) and a.count('3') > 0 \
                and a.count('5') > 0 and a.count('7') > 0 and str(int(a)).count('0') == 0:
            return 1
        else:
            return 0

    ret1 = dfs(a + '0', depth + 1)
    ret2 = dfs(a + '3', depth + 1)
    ret3 = dfs(a + '5', depth + 1)
    ret4 = dfs(a + '7', depth + 1)
    return ret1 + ret2 + ret3 + ret4


ans = dfs('', 0)
print(ans)
# print(t)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
cnt = []

def search(x, use):
    if x > n:
        return
    if use == 0b111:
        cnt.append(1)
        
    search(x * 10 + 3, use | 0b100)
    search(x * 10 + 5, use | 0b010)
    search(x * 10 + 7, use | 0b001)

search(0, 0)
print(sum(cnt))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

n = int(input())

def search(x, use, cnt):
    if x > n:
        return
    if use == 0b111:
        cnt.append(1)
        
    search(x * 10 + 3, use | 0b100, cnt)
    search(x * 10 + 5, use | 0b010, cnt)
    search(x * 10 + 7, use | 0b001, cnt)

res = []
search(0, 0, res)
print(sum(res))

Submission status: Accepted

Solution code:
n = int(input())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

if n < 357:
    print(0)
else:
    ans = 0
    for i in range(3, 10):
        for j in range(3**i):
            a = ''
            val = Base_10_to_n(j, 3).zfill(i)
            for k in val:
                if k == '1':
                    a += '3'
                elif k == '2':
                    a += '5'
                else:
                    a += '7'
            if len(set(a)) == 3 and n >= int(a):
                ans += 1
    print(ans)

Submission status: Accepted

Solution code:
n = input()
from itertools import product
sum = 0
for i in range(len(n)-2):
  for j in list(product("753", repeat=i+3)):
    if int(''.join(j)) <= int(n) and len(set(j))==3:
      sum+=1
print(sum)

Submission status: Accepted

Solution code:
N = input()
n = len(N)
ans = 0
if n < 3:
    print(0)
    exit()
if n > 3:
    for i in range(3,n):
        ans += 3**i - 3*(2**i) + 3
a = int(N[0])
if a > 3:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
if a > 5:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
if a > 7:
    ans += 3**(n-1) - 2*(2**(n-1)) + 1
b = int(N[1])
c = int(N[2])
if a == 3:
    if b > 3:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b > 5:
        ans += 3**(n-2) - (2**(n-2))
    if b > 7:
        ans += 3**(n-2) - (2**(n-2))
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - 2*(2**(n-3)) + 1
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 5:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3)
    if b == 7:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3)
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
elif a == 5:
    if b > 3:
        ans += 3**(n-2) - (2**(n-2))
    if b > 5:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b > 7:
        ans += 3**(n-2) - (2**(n-2))
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3)
    if b == 5:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - 2*(2**(n-3)) + 1
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 7:
        if c > 3:
            ans += 3**(n-3)
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
elif a == 7:
    if b > 3:
        ans += 3**(n-2) - (2**(n-2))
    if b > 5:
        ans += 3**(n-2) - (2**(n-2))
    if b > 7:
        ans += 3**(n-2) - 2*(2**(n-2)) + 1
    if b == 3:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3)
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 5:
        if c > 3:
            ans += 3**(n-3)
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - (2**(n-3))
    if b == 7:
        if c > 3:
            ans += 3**(n-3) - (2**(n-3))
        if c > 5:
            ans += 3**(n-3) - (2**(n-3))
        if c > 7:
            ans += 3**(n-3) - 2*(2**(n-3)) + 1
    
if (a == 3 or a == 5 or a == 7) and (b == 3 or b == 5 or b == 7) and (c == 3 or c == 5 or c == 7):
    d = (a*100 + b * 10 + c) * 10**(n-3)
    e = int(N) + 1
    t = {"3","5","7"}
    for i in range(d,e):
        u = set(str(i))
        if u == t:
            ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque


# from decorator import stop_watch
#
#
# @stop_watch
def solve(N):
    dq = deque([(3, {3: 1, 5: 0, 7: 0}),
                (5, {3: 0, 5: 1, 7: 0}),
                (7, {3: 0, 5: 0, 7: 1})])
    ans = 0
    while dq:
        num, check = dq.popleft()
        if num > N:
            break
        if sum(check.values()) == 3:
            ans += 1
        for i in (3, 5, 7):
            new_num = num * 10 + i
            if new_num > N:
                break
            new_check = check.copy()
            new_check[i] = 1
            dq.append((new_num, new_check))
    print(ans)


if __name__ == '__main__':
    N = int(input())
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N):
    dq = deque([(3, [1, 0, 0]), (5, [0, 1, 0]), (7, [0, 0, 1])])
    ans = 0
    while dq:
        num, check = dq.popleft()
        if num > N:
            break
        if sum(check) == 3:
            ans += 1
        for i in (3, 5, 7):
            new_num = num * 10 + i
            if new_num > N:
                break
            new_check = check.copy()
            if i == 3:
                new_check[0] = 1
            elif i == 5:
                new_check[1] = 1
            elif i == 7:
                new_check[2] = 1
            dq.append((new_num, new_check))
    print(ans)


if __name__ == '__main__':
    N = int(input())
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

Submission status: Accepted

Solution code:
import itertools

def main():
    n = int(input())
    tar_list = []
    cnt = 0
    
    for a in range(3,len(str(n))+1):
        target = list(itertools.product([3, 5, 7], repeat=a))
        #print(target)
        for tar in target:
            tar_list = list(tar)
            if tar.count(3) > 0 and tar.count(5) > 0 and  tar.count(7):
                #print(tar_list)
                ans = 0
                i = a-1
                for ii in tar_list:
                    ans += ii*(10**i)
                    #print(ans)
                    i -= 1
                if ans <= n:
                    cnt +=1
        
    print(cnt)
                    
            
            
            
        
               
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    def dfs(n, used):
        if n > N:
            return 0
        ans = 0
        if used == 7:
            ans += 1
        for i, d in enumerate((3, 5, 7)):
            ans += dfs(10 * n + d, used | (1 << i))
        return ans

    print(dfs(0, 0))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools


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

    # 7, 5, 3 だけでできている数をピックアップ
    cnt = 0
    for i in range(3, len(str(N)) + 1):
        for j in itertools.product([3, 5, 7], repeat=i):
            p = 0
            for a, b in enumerate(j[::-1]):
                p += b * 10 ** a

            if p > N:
                break

            # 3, 5, 7全てあるのを抽出
            if len(set(j)) == 3:
                cnt += 1

    print(cnt)


main()

Submission status: Accepted

Solution code:
# coding:UTF-8
import sys
from math import factorial


def comb(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


def perm(n, r):
    return factorial(n) // factorial(r)


def resultSur97(x):
    return x % (10 ** 9 + 7)

def dfs(s,n):
    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, n)
    return ret

if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    a = int(input())    # 数字

    # ------ 処理 ------#



    # ------ 出力 ------#
    print("{}".format(dfs("0", a)))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")

Submission status: Accepted

Solution code:
N= int(input())
Nstr = str(N)
Box = ['3','5','7']
Boxi = set(Box)
Box = []
Box2 = set()
for _ in range(10**9):
    B = Boxi.pop()
    if len(B) < len(Nstr) and int(B) <= N:
        Boxi.add('3'+B)
        Boxi.add('5'+B)
        Boxi.add('7'+B)
        Box2.add('3'+B)
        Box2.add('5'+B)
        Box2.add('7'+B)
    if Boxi == set():
      break
for i in Box2:
    Bint = int(i)
    if Bint <= N and '3' in i and '5' in i and '7' in i:
        Box.append(Bint)
print(len(Box))

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N=intput()
ans=0
for i in range(1,div10(N)+1):
    for x in product('357',repeat=i):
        if x.count('3')*x.count('5')*x.count('7')>0 and int(''.join(x))<=N:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque

def dfs(n):
    stack = deque(['3','5','7'])
    ansl = []
    while stack:
        num_s = stack.pop()
        num = int(num_s)
        if num > n: continue
        if '7' in num_s and '5' in num_s and '3' in num_s:
            ansl.append(num)
        stack.append(num_s+'7')
        stack.append(num_s+'5')
        stack.append(num_s+'3')
    return ansl


def main():
    n = int(input())
    ansl = dfs(n)
    print(len(ansl))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())

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

ans = 0
for i in range(3, len(str(n))):
    ans += 3**i - 3*(2**i) + 3

for i in product(['3', '5', '7'], repeat=len(str(n))):
    if '3' in i and '5' in i and '7' in i:
        if int(''.join(i)) <= n:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

ans="0"
cnt=0
l=["3","5","7"]

def dfs(now):
  global cnt

  if n<int(now):
    return now
  now=str(now)
  if 1<=now.count("3") and 1<=now.count("5") and 1<=now.count("7"):
    cnt+=1

  for i in l:
    a=now+i
    dfs(a)
  
  return cnt
print(dfs(ans))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    def rec(n, used):
        ans = 0
        if used == 7:
            ans += 1
        for i, d in enumerate((3, 7, 5)):
            if 10 * n + d <= N:
                ans += rec(10 * n + d, used | (1 << i))
        return ans

    print(rec(0, 0))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    def rec(n, used):
        ans = 0
        if all(used):
            ans += 1
        for i, d in enumerate((3, 7, 5)):
            if 10 * n + d <= N:
                cur = used[i]
                used[i] = True
                ans += rec(10 * n + d, used)
                used[i] = cur
        return ans

    print(rec(0, [False, False, False]))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

def dfs(cur, use, cnt):
    if cur > n:
        return
    if use == 0b111:
        cnt.append(1)

    dfs(cur*10+7, use|0b001, cnt)
    dfs(cur*10+5, use|0b010, cnt)
    dfs(cur*10+3, use|0b100, cnt)

cnt = []
dfs(0, 0, cnt)
print(len(cnt))

Submission status: Accepted

Solution code:
import itertools

def main():
    N = int(input())
    if N < 100:
        print(0)
        exit()
    ans = 0
    for rep in range(3, len(str(N))+1):
        for comb in itertools.product(["3", "5", "7"], repeat=rep):
            if len(set(comb)) != 3:
                continue
            if int("".join(comb)) <= N:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

def f(num, use, counter):
    if num >N:
        return
    if use == 0b111:
        counter.append(1)
    f(num*10 + 7, use | 0b001, counter)
    f(num*10 + 5, use | 0b010, counter)
    f(num*10 + 3, use | 0b100, counter)

ans = []
f(0, 0, ans)
print(sum(ans))

Submission status: Accepted

Solution code:
def f(v, K):
    global cnt
    v += str(K)
    if len(v) == len_ and int(v) <= N:
        if len(set(v)) == 3:
            cnt += 1
        return
    elif len(v) == len_:
        return
    f(v, 7)
    f(v, 5)
    f(v, 3)

N = int(input())
total = [0, 0]
for i in range(3, 10):
    temp = 3**i - (2**i*3 - 3)
    total.append(temp)
len_ = len(str(N))
ans = sum(total[:len_-1])
cnt = 0
f('','')
ans += cnt
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    list = [[3, 5, 7]]
    N=int(input())
    for i in range(9):
        new = []
        for j in list[-1]:
            a = 10 * j
            new.append(a + 3)
            new.append(a + 5)
            new.append(a + 7)
        list.append(new)

    pass
    count =0
    for sub in list:
        for j in sub:
            s =str(j)
            if j>N:
                print(count)
                exit()
            if "3" in s and "7" in s and "5" in s:
                count +=1






if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools


# \n
def input():
    return sys.stdin.readline().rstrip()


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

    A = int(math.log10(N))
    flag=0
    count =0
    for a in range(3,A+2):

        for i in itertools.product([3,5,7],repeat=a):
            digit=0
            if 3 in i and  5 in i and 7 in i:


                for s in range(a):
                    digit+=10**(a-s-1)*i[s]
                if digit <=N:
                    count+=1
                else:
                    break
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())
T = ["3", "5", "7"]
l = T.copy()
ans = 0
while l:
    n = l.pop()
    if int(n) > N:
        continue
    if len(set(n)) == 3:
        ans += 1
    for t in T:
        l.append(n + t)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n_str = input()
n = int(n_str)
e_list = ["3", "5", "7"]
ans = 0
for i in range(3, len(n_str) + 1):
    for temp in list(product(e_list, repeat=i)):
        if "3" in temp and "5" in temp and "7" in temp:
            num = int("".join(temp))
            if num <= n:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n_str = input()
n = int(n_str)
l = len(n_str)
e_list = ["3", "5", "7"]
ans = 0
for i in range(3, l + 1):
    for temp in list(product(e_list, repeat=i)):
        if "3" in temp and "5" in temp and "7" in temp:
            num = int("".join(temp))
            if num <= n:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n_str = input()
n = int(n_str)
ans = 0
for i in range(3, len(n_str) + 1):
    for temp in list(product(["3", "5", "7"], repeat=i)):
        if "3" in temp and "5" in temp and "7" in temp and int("".join(temp)) <= n:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = str(input())
Keta = len(N)
N_List = ["3","5","7"]

Ans = 0
for i in range(3,Keta):
    Ans += 3**i
    Ans -= (2**i*3) -3

N = int(N)

if Keta >= 3:
    for Moji in itertools.product(N_List, repeat=Keta):
        Moji_Kazu = len(set(Moji))
        Str_Number = int("".join(Moji))
        if (Str_Number <= N) & (Moji_Kazu == 3):
            Ans += 1
    
print(Ans)

Submission status: Accepted

Solution code:
from itertools import product
n_str = input()
n = int(n_str)
ans = 0
for i in range(3, len(n_str) + 1):
    for temp in list(product(["3", "5", "7"], repeat=i)):
        temp_set = set(temp)
        if "3" in temp_set and "5" in temp_set and "7" in temp_set and int("".join(temp)) <= n:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import bisect
def dfs(cnt, s, three, five, seven):
    if cnt == 10:
        return
    if s != "" and min(three, five, seven) > 0:
        v.append(int(s))
    dfs(cnt+1, "3"+s, three+1, five, seven)
    dfs(cnt+1, "5"+s, three, five+1, seven)
    dfs(cnt+1, "7"+s, three, five, seven+1)


v = []
dfs(0, "", 0, 0, 0)
v.sort()

n = int(input())
print(bisect.bisect_right(v, n))

Submission status: Accepted

Solution code:
N = int(input())

# 4**9 = 2**18 <= 10^6

def dfs(keta,x):
    if x > N:
        return 0
    if keta == 9:
        three = 0
        five = 0
        seven = 0
        while x:
            if x % 10 == 3:
                three += 1
            elif x % 10 == 5:
                five += 1
            elif x % 10 == 7:
                seven += 1
            else:
                return 0
            x //= 10
        if three > 0 and five > 0 and seven > 0:
            return 1
    else:
        ans = 0
        x *= 10
        ans += dfs(keta+1,x)
        ans += dfs(keta+1,x+3)
        ans += dfs(keta+1,x+5)
        ans += dfs(keta+1,x+7)
        return ans
    return 0

print(dfs(0,0))

Submission status: Accepted

Solution code:
n = int(input())
ln =len(str(n))

if ln ==10:
    ln =9

res = 0

from collections import Counter
import itertools
seq =("3","5","7")

for i in range(3,ln+1):
    temp = list(itertools.product(seq, repeat = i))
    for j in temp:
        ja = Counter(j)
        if ja["3"] * ja["5"] * ja["7"] >0:
            jj = ''.join(j)
            tempp = int(jj)
            if tempp <= n:
                res +=1

print(res)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
count = 0
for i in range(3, len(str(N)) + 1):
    for j in itertools.product('753', repeat=i):
        if int(''.join(j)) <= N and '3' in str(j) and '5'in str(j) and '7' in str(j):
            count += 1

print(count)