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:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
# stupid = 0
# for i in range(1, n + 1):
#     num = str(i)
#     cnt7 = 0
#     cnt5 = 0
#     cnt3 = 0
#     ok = True
#     for j in num:
#         if j == "7":
#             cnt7 += 1
#         elif j == "5":
#             cnt5 += 1
#         elif j == "3":
#             cnt3 += 1
#         else:
#             ok = False
#             break
#     if (not ok) or cnt7 == 0 or cnt5 == 0 or cnt3 == 0:
#         continue
#     # print("i =", i)
#     stupid += 1
# print("stupid =", stupid)



m = len(str(n)) 
# print(n, m)
# print("m =", m)
x = [0 for i in range(9)]
for i in range(3, 9):
    x[i] = 3 ** i  - (2 ** i - 2) * 3 - 3
# print("x =", x)

ans = 0
for i in range(m):
    ans += x[i]

def dfs(cnt, ret, n, m):
    if cnt == m:
        # print("ret =", ret)
        cnt7 = 0
        cnt5 = 0
        cnt3 = 0
        for i in ret:
            if i == "7":
                cnt7 += 1
            elif i == "5":
                cnt5 += 1
            else:
                cnt3 += 1
        if cnt7 == 0 or cnt5 == 0 or cnt3 == 0:
            return
        if int(ret) <= n:
            global ans
            ans += 1
        return
    dfs(cnt + 1, ret + "7", n, m)
    dfs(cnt + 1, ret + "5", n, m)
    dfs(cnt + 1, ret + "3", n, m)
    return 

dfs(0, "", n, m)

print(int(ans))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2000000)

n=int(input())
three=['3','5','7']


ans=[]
def search(dfs):
    newdfs=[]
    for moto in dfs:
        for i in three:
            new=moto+i
            threeok=[False for k in range(3)]
            if int(new)>n:
                return
            for m in list(new):
                for j in range(3):
                    if m==three[j]:
                        threeok[j]=True
                        break
            if False not in threeok:
                ans.append(new)
            newdfs.append(new)
    search(newdfs)

search(three)

print(len(ans))

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

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)

N = inputI()

dic = [[3,5,7]]


for _ in range(8):
  temp = []
  for v in dic[-1]:
    temp.append(v*10+3)
    temp.append(v*10+5) 
    temp.append(v*10+7)
  dic.append(temp)

x = []
for item in dic:
  x += item
nx = []
for i in x:
  if len(set(list(str(i)))) == 3:
    nx.append(i)

print(bisect.bisect(nx,N))

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
rength = len(str(N))
numlist = [3, 5, 7]
cnt = 0

def sevfivthr(i, strint):
    global cnt
    if i == rength:
        return
    else:
        for num in numlist:
            newstr = strint + str(num)
            if ('3' in newstr) and ('5' in newstr) and ('7' in newstr):
                if int(newstr) <= N:
                    cnt += 1
            sevfivthr(i + 1, newstr)
for i in numlist:
    sevfivthr(1, str(i))
print(cnt)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


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

    def f(s):
        if int(s) > N:
            return 0
        p = 0
        if len(set(list(s))) == 3:
            p = 1
        return f(s + "3") + f(s + "5") + f(s + "7") + p

    answer = f("3") + f("5") + f("7")
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    q = deque([3, 5, 7])
    answer = 0
    d = 3
    while d <= N:
        d = q.popleft()
        if len(set(list(str(d)))) == 3 and d <= N:
            answer += 1
        q.append(d * 10 + 3)
        q.append(d * 10 + 5)
        q.append(d * 10 + 7)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def bfs(N):
    q = deque(["3", "5", "7"])

    cnt = 0
    while q:
        s = q.popleft()

        if int(s) > N:
            continue

        if len(set(s)) == 3:
            cnt += 1

        for c in ["3", "5", "7"]:
            q.append(s + c)

    return cnt


def main():
    N = int(input())
    ans = bfs(N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
ans = 0

def dfs(current_num, seven, five, three, n):
    if current_num > n:
        return
    
    if seven == 1 & five == 1 & three == 1:
        global ans
        ans += 1
    
    dfs(10 * current_num + 7, 1, five, three, n)
    dfs(10 * current_num + 5, seven, 1, three, n)
    dfs(10 * current_num + 3, seven, five, 1, n)

def solve_C():
    n = int(input())

    dfs(0, 0, 0, 0, n)
    return ans

print(solve_C())

Submission status: Accepted

Solution code:
N = int(input())
count = 0
item = [3, 5, 7]

def dfs(s):
    global count
    if s > N:
        return
    string = str(s)
    if '3' in string and '5' in string and '7' in string:
        count += 1
    dfs(10*s + 3)
    dfs(10*s + 5)
    dfs(10*s + 7)

dfs(0)
print(count)

Submission status: Accepted

Solution code:
N = int(input())
import sys
sys.setrecursionlimit(500000)
def dfs(l):
    global N

    if l!=[] and N<int("".join(l)):
        return 0
    ans = 0
    if all(l.count(i)>0 for i in ["3", "5", "7"]):
        ans = 1
    for i in ["3", "5", "7"]:
        l.append(i)
        #参照渡し
        ans += dfs(l)
        l.pop()

    return ans

print(dfs([]))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()

a = [3,5,7]

cnt = 0

for i in range(3, len(N)):
	for x in product(a, repeat=i):
		##print(x, len(set(x)))
		if len(set(x)) == 3:
			cnt += 1
			#print(x)

for x in product(a, repeat=len(N)):
	##print(x, len(set(x)))
	if len(set(x)) == 3:
		#print(x)
		p = 0
		for i in range(len(N)):
			p += x[-(i+1)]*10**i
		if int(N) < p:
			print(cnt)
			break
		cnt += 1
else:
	print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
def main():
    def is_753(s):
        return '7' in s and '5' in s and '3' in s

    S = input()
    N = int(S)
    r = 0
    for i in range(len(S)):
        for j in product('753', repeat=i + 1):
            t = ''.join(j)
            if int(t) <= N and is_753(t):
                r += 1
    return r
print(main())

Submission status: Accepted

Solution code:
def dfs(s, n):
    if int(s) > n:
        return 0
    cnt = 0
    if "7" in s and "5" in s and "3" in s:#もし753数だったら
        cnt += 1
    return cnt + dfs(s + "7", n) + dfs(s + "5", n) + dfs(s + "3", n)#sに７か５か３を加えた数について、再帰的に探索

n = int(input())
print((dfs("0", n)))#int("07") = 7なので、0つけてOK

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 collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

N = I()
def dfs(s, n):
    if int(s) > n:
        return 0
    count = 0
    if '7' in s and '5' in s and '3' in s:
        count += 1
    return count + dfs(s+'7', n) + dfs(s+'5', n) + dfs(s+'3', n)
print(dfs('0', N))

Submission status: Accepted

Solution code:
N = int(input())

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

    ans = 1 if all(x.count(c)  for c in "753") > 0 else 0

    for n in "753":
        ans += dfs(x+n)

    return ans


print(dfs("0"))

Submission status: Accepted

Solution code:
s = input()
l = len(s)
n = int(s)
ans = 0
import itertools
for li in range(3, l+1):
    for i in itertools.product([7, 5, 3], repeat=li):
        if len(set(i)) != 3:
            continue
        num = int(''.join(map(str, i)))
        if num <= n:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
n = int(s)
ans = 0
import itertools
for li in range(3, l+1):
    for i in itertools.product([7, 5, 3], repeat=li):
        num = int(''.join(map(str, i)))
        if num > n:
            continue
        if len(set(i)) == 3:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc114/tasks/abc114_c

n = int(input())

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 ['7', '5', '3']:
        ret += dfs(s + c, n)
    return ret

ans = dfs('0', n)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
count = 0
def dfs(x):
    global count
    if x <= n and len(set(str(x)))==3:
        count += 1

    x *= 10
    for i in [3, 5, 7]:
        if x > n: continue
        x += i
        dfs(x)
        x -= i
dfs(0)
print(count)

Submission status: Accepted

Solution code:
import math
def main():
    n=int(input())
    if n<357:
        print(0)
    else:
        numRange=math.ceil(math.log10(n))
        num=[0]*numRange
        num[0:3]=[0,1,1]
        check=0
        ans=0
        for i in range((3**(numRange+1)-1)//2-13):
            num[0]+=1
            j=0
            while j<numRange-1 and num[j]==4:
                num[j+1]+=1
                num[j]=1
                j+=1
            if 1 in num and 2 in num and 3 in num:
                j=0
                check=0
                while j<numRange and num[j]!=0:
                    a=0
                    if num[j]==1:
                        a=3
                    elif num[j]==2:
                        a=5
                    else:
                        a=7
                    check+=a*10**j
                    j+=1
                if check<=n:
                    ans+=1
                else:
                    break
        print(ans)
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

n = int(input())
count = 0
for i in range(3,10):
    li = list(itertools.product(range(3), repeat=i))
    #print(li)
    for l in li:
        st = ''
        for ll in l:
            if ll == 0:
                st += '3'
            elif ll == 1:
                st += '5'
            else:
                st += '7'
        if len(set(list(st))) == 3 and int(st)<=n:
            count += 1
print(count)

Submission status: Accepted

Solution code:
s = input()
n = int(s)
l = len(s)

dp = [[] for _ in range(l+1)]
dp[0].append('')

for i in range(l):
  for e in dp[i]:
    dp[i+1].append(e+'3')
    dp[i+1].append(e+'5')
    dp[i+1].append(e+'7')
ans = 0

for i in range(min(3,l+1),l+1):
  for e in dp[i]:
    if '3' in e and '5' in e and '7' in e and int(e) <= n:
      ans += 1
      
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def f(x):
    if int(x) > N:
        return 0
    else:
        if all(x.count(j) >= 1 for j in ["3", "5", "7"]):
            ans = 1
        else:
            ans = 0
        for i in ["3", "5", "7"]:
            ans += f(x+i)    
        return ans        

print(f("0"))

Submission status: Accepted

Solution code:
def generator(n=9):
    if n == 0:
        yield 0
    else:
        for a in generator(n - 1):
            for i in (0, 3, 5, 7):
                yield 10 * a + i


n = int(input())
cnt = 0
for a in generator():
    if a > n:
        break
    if set(str(a)) == {'3', '5', '7'}:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
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
def main():
    global n
    n=int(input())
    print(dfs('0'))

if __name__=='__main__':
    main()

Submission status: Accepted

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



def solve(N: int):
    from itertools import product, count, takewhile
    ans = 0
    for i in range(10):
        for s in product('357', repeat=i):
            if any(c not in s for c in '357'):
                continue
            if int(''.join(s)) <= N:
                ans += 1
    return ans


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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



def solve(N: int):
    from itertools import product, count, takewhile
    ans = 0
    for i in range(10):
        for s in product('357', repeat=i):
            if not('3' in s and '5' in s and '7' in s):
                continue
            if int(''.join(s)) <= N:
                ans += 1
    return ans


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

n = int(readline())
cnt = 0
q = ['3', '5', '7']
while q:
    qq = q.pop()
    v = list(qq)
    if '3' in v and '5' in v and '7' in v:
        cnt += 1
    if int(qq + '3') <= n:
        q.append(qq + '3')
        if int(qq + '5') <= n:
            q.append(qq + '5')
            if int(qq + '7') <= n:
                q.append(qq + '7')
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
def dfs(tmp,num):
    if tmp > n:
        return
    if num == 0b111:
        cnt[0]+=1
    dfs(tmp*10+7, num | 0b001)
    dfs(tmp*10+5,num | 0b010)
    dfs(tmp*10+3,num | 0b100)
    
cnt=[0]
dfs(0,0)
print(cnt[0])

Submission status: Accepted

Solution code:
def dfs(cur, use):
    if cur > N:
        return
    if use == 0b111:
        cnt[0] += 1
    dfs(cur*10 + 3, use | 0b001)
    dfs(cur*10 + 5, use | 0b010)
    dfs(cur*10 + 7, use | 0b100)
    return

N = int(input())
cnt = [0]
dfs(0, 0)
print(cnt[0])

Submission status: Accepted

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    digit = len(str(n))
    ans = 0
    for i in range(3, digit):
        # 3 桁 to digit-1 桁
        p = product([3, 5, 7], repeat=i)
        for l in p:
            if len(list(set(l))) == 3:
                ans += 1
    # print(ans)
    p = product([3, 5, 7], repeat=digit)
    for l in p:
        if len(list(set(l))) == 3 and int(''.join(map(str, l))) <= n:
            ans += 1
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools


def main():
    N = int(input())
    L = len(str(N))
    cnt = 0
    for length in range(3, L + 1):
        for semi_753 in itertools.product(['3', '5', '7'], repeat=length):
            n_str = ''.join(semi_753)
            if '3' in n_str and '5' in n_str and '7' in n_str:
                n = int(n_str)
                if n <= N:
                    cnt += 1
    print(cnt)


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)


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

Submission status: Accepted

Solution code:
import itertools
N = int(input())
ans = 0
for i in range(3, 10):
    product = list(itertools.product(['3', '5', '7'], repeat=i))
    for li in product:
        if len(set(li)) == 3:
            if int(''.join(li)) <= N:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

d=['3','5','7','']
k=10
a=d
def make(k,l):
    if k==0:
        return l
    t=set()
    for i in l:
        for j in d:
            t.add(i+j)
    return make(k-1,t)

s=[]    
for i in make(k,d):
    if i!='':
        u=set()
        for j in i:
            u.add(j)
        if len(u)==3:
            s.append(int(i))

ans=sum([1 if x<=n else 0 for x in s])
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

readline = stdin.buffer.readline

INF = 10 ** 10

N = int(readline())

cnt = 0

def dfs(A):
    global cnt
    if int(''.join(A)) > N:
        return
    
    if len(set(A)) == 4:
        cnt += 1
    
    
    for i in ["3", "5", "7"]:
        A.append(i)
        dfs(A)
        A.pop()


dfs(["0"])

print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

readline = stdin.buffer.readline

INF = 10 ** 10

N = int(readline())

cnt = 0

def dfs(A):
    global cnt
    if int(''.join(A)) > N:
        return
    
    if "3" in A and "5" in A and "7" in A:
        cnt += 1
    
    
    for i in ["3", "5", "7"]:
        A.append(i)
        dfs(A)
        A.pop()


dfs(["0"])

print(cnt)

Submission status: Accepted

Solution code:
import itertools
import math


def main():
  n = int(input())
  
  count_753 = 0
  max_digits = int(math.log10(n)) + 2
  cand_753 = ("3", "5", "7")
  
  for digits in range(3, max_digits):
    for dig_753 in itertools.product(cand_753, repeat=digits):
      number_str = "".join(dig_753)
      
      if "7" in number_str and "5" in number_str and "3" in number_str and int(number_str) <= n:
        count_753 += 1
  
  print(count_753)

if __name__ == "__main__":
  main()

Submission status: Accepted

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

N = int(readline())

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


def main():
    print(dfs('0'))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    N = int(readline())
    que = []
    for val in ['357', '375', '537', '573', '735', '753']:
        if int(val) <= N:
            que.append(val)
    res = set(que)
    que = deque(que)
    while que:
        pre = que.popleft()
        for p in ['3', '5', '7']:
            for i in range(len(pre)+1):
                next = pre[:i] + p + pre[i:]
                if int(next) <= N and next not in res:
                    que.append(next)
                    res.add(next)

    print(len(res))

if __name__ == '__main__':
    main()