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:
""" AtCoder """

N = int(int(input()))

l = []

def f(n):
    if len(n) < 10:
        a = n + '7'
        b = n + '5'
        c = n + '3'
        if '7' in a and '5' in a and '3' in a:
            l.append(int(a))
        if '7' in b and '5' in b and '3' in b:
            l.append(int(b))
        if '7' in c and '5' in c and '3' in c:
            l.append(int(c))
        f(a)
        f(b)
        f(c)

f('')

l.sort()

for i in range(len(l)):
    if int(l[i]) > N:
        print(i)
        break

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for n1 in ['0','3','5','7']:
	for n2 in ['0','3','5','7']:
		for n3 in ['0','3','5','7']:
			for n4 in ['0','3','5','7']:
				for n5 in ['0','3','5','7']:
					for n6 in ['0','3','5','7']:
						for n7 in ['0','3','5','7']:
							for n8 in ['0','3','5','7']:
								for n9 in ['0','3','5','7']:
									target = int(n1+n2+n3+n4+n5+n6+n7+n8+n9)
									if N <target:
										continue
										
									if 0 <str(target).count('0'):
										continue
										
									if str(target).count('3')==0:
										continue
										
									if str(target).count('5')==0:
										continue
										
									if str(target).count('7')==0:
										continue
									#print(target)
									ans +=1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
num=[]
def dfs(s,x):
    if x==len(str(n)):
        return
    else:
        num.append(int(s+"3"))
        num.append(int(s+"5"))
        num.append(int(s+"7"))
        dfs(s+"3",x+1)
        dfs(s+"5",x+1)
        dfs(s+"7",x+1)
dfs("",0)
num=sorted(set(num))
ans=0
for i in num:
    if i<=n and str(i).count("3")*str(i).count("5")*str(i).count("7")!=0:
        ans+=1
print(ans)

Submission status: Accepted

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


n = int(input())
print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
def dfs(n=0,a=0,b=0,c=0):
    if n > N:
        return
    if a*b*c > 0:
        global ans
        ans += 1
    dfs(10*n+3,a+1,b,c)
    dfs(10*n+5,a,b+1,c)
    dfs(10*n+7,a,b,c+1)

dfs()
print(ans)

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
ans = 0
option = ["7","5","3"]
dq = deque()
for s in option:
    dq.append(s)

def judge(string):
    bit = [0]*3
    chenge = {"7":0, "5":1, "3":2}
    for s in string:
        bit[chenge[s]] = 1
    return all(bit)

while dq:
    n = dq.popleft()
    if int(n) <= N and judge(n):
        ans += 1
    if int(n) > N:
        continue
    for i,s in enumerate(option):
        dq.append(n+s)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
import math

S = input()
n = int(S)

def create357(length):
    if length == 1:
        return [["3",2],["5",3],["7",5]]
    else:
        ans = []
        for s in create357(length-1):
            ans.append([s[0]+"3",s[1]*2])
            ans.append([s[0]+"5",s[1]*3])
            ans.append([s[0]+"7",s[1]*5])
        return ans

if n < 1000:
    ans = 0
    for st,i in create357(3):
        if i%30 == 0 and n >= int(st):
            ans += 1
    print(ans)

else:
    ans = 0
    digit = len(S)
    for d in range(2,digit-1):
        length = d+1
        ans += 3**length+3-3*2**length
    for st,i in create357(digit):
        if i%30 == 0 and n >= int(st):
            ans += 1
    print(int(ans))

Submission status: Accepted

Solution code:
import itertools
from collections import Counter
import bisect
a = []
for i in range(3, 10):
    for j in itertools.product(["3", "5", "7"], repeat=i):
        if len(Counter(j)) == 3:
            a.append(int("".join(j)))
n = int(input())
print(bisect.bisect_right(a, n))

Submission status: Accepted

Solution code:
N = input()
A = ['7','5','3','']
num = ['']
for i in range(len(N)):
    num2 = []
    for n in num:
        for a in A:
            num2.append(n+a)
    num = num2

ans = []
for m in num:
    if len(set(m)) == 3 and int(m) <= int(N):
        ans.append(m)

print(len(set(ans)))