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 itertools
import bisect

a = []
for i in range(3, 10):
    for j in itertools.product([3, 5, 7], repeat=i):
        if j.count(3) > 0 and j.count(5) > 0 and j.count(7) > 0:
            a.append(int("".join(map(str, j))))
a.sort()
n = int(input())
print(bisect.bisect_right(a, n))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - 755
TLE
"""
def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            if r == 0 and n:
                return '0'
            res.append(str(str(r)))
        if not res:
            res = ['0']
        return ''.join(res[::-1]).translate(str.maketrans('0123', '0357'))

    n = 0
    while True:
        t = conv(n)
        while '0' in t or len(set(list(t))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if int(t) > n:
            break
        ans += 1
    return ans


n = int(input())
ans = solve(n)
print(ans)

Submission status: Accepted

Solution code:
def is753(num):
    d = str(num)
    if d.count("3") > 0 and d.count("5") > 0 and d.count("7") > 0:
        return(True)
    else:
        return(False)

def loop753(N, num):
    global counter
    if num <= N:
        if is753(num):
            counter += 1
    else:
        return

    loop753(N, num * 10 + 3)
    loop753(N, num * 10 + 5)
    loop753(N, num * 10 + 7)

counter = 0
NN = int(input())
loop753(NN, 0)
print(counter)

Submission status: Accepted

Solution code:
from itertools import product

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

  results = list()
  ans = 0

  for i in range(1, 10):
    for j in list(product(['3', '5', '7'], repeat=i)):
      results.append(''.join(map(str, list(j))))
  
  for result in results:
    if int(result) > N:
      break
    if '3' in result and '5' in result and '7' in result:
      ans +=1

  print(ans)


main()

Submission status: Accepted

Solution code:
N=raw_input()
l=len(N)
 
s="375"


def func(n):
	#print "func ::: ", n
	ret=0
	if len(n) == 0 :
		ret+=func(n+"3")
		ret+=func(n+"5")
		ret+=func(n+"7")
	elif  int(n)<=int(N):
		for i in s:
			if i not in n:
				ret=0
				break
		else:
			ret=1

		ret+=func(n+"3")
		ret+=func(n+"5")
		ret+=func(n+"7")
	return ret

print func("")

Submission status: Accepted

Solution code:
N=raw_input()

l=len(N)

s="375"

ans=0
def func(t):
	global ans
	#print "func( ", t, " )", len(t)
	if len(t)>len(N):
		return
	else:
		for si in s:
			if si not in t:
				break
		else:
			if int(t)<=int(N):
				ans+=1
	func(t+"3")
	func(t+"5")
	func(t+"7")

	return ans

print func("")

Submission status: Accepted

Solution code:
N=input()

l=len( str(N) )

s="357"

P=[ set() for i in range(l+1) ]   #Pattern
P[0].add(0)

for i in range(1,l+1):
	k=l-i	#keta
	for x in P[i-1]:
		for j in s:
			j=int(j)
			P[i].add(  x+(10**k)*j )
			P[i].add( 0 )


ans=0
for x in P[-1]:
	if  1<= x <= N:
		for i in s:
			if i not in str(x):
				break
		else:
			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
    for c in '753':
        ret += dfs(s + c)
    return ret
print(dfs('0'))

Submission status: Accepted

Solution code:
values = []


def dfs(n, x):
    if x <= n:
        str_x = str(x)
        if str_x.count('3') > 0 and str_x.count('5') > 0 and str_x.count('7') > 0:
            values.append(x)
    else:
        return

    if x <= 10 ** 9:
        dfs(n, 10 * x + 3)
        dfs(n, 10 * x + 5)
        dfs(n, 10 * x + 7)


def main():
    n = int(input())
    dfs(n, 0)
    print(len(values))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

def dfs(n, a, b, c):
    if n > N: return 0
    ret = 1 if a and b and c else 0
    ret += dfs(n*10+3, True, b, c) + dfs(n*10+5, a, True, c) + dfs(n*10+7, a, b, True)
    return ret

print(dfs(0, False, False, False))

Submission status: Accepted

Solution code:
n = int(input())

def solve(s):
    if int(s) > n:
        return 0
    if '7' in s and '5' in s and '3' in s:
        count = 1
    else:
        count = 0
    count += solve(s + '7')
    count += solve(s + '5')
    count += solve(s + '3')
    return count

print(solve('0'))

Submission status: Accepted

Solution code:
def solve(N):
    stack = ["3", "5", "7"]
    count = 0

    while len(stack) > 0:
        s = stack.pop()
        if int(s) <= N: 
            count += int(all([c in s for c in "753"]))
            for c in "753":
                stack.append(s + c)
    return count
    

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

N = input()
n = int(N)

ret = 0
for x in range(3, len(N) + 1):
    for y in itertools.product('357', repeat=x):
        if len(set(y)) == 3 and int(''.join(y)) <= n:
            ret += 1
print(ret)

Submission status: Accepted

Solution code:
import itertools

N = int(raw_input())
count = 0

for i in range(3,10):
	for j in itertools.product("357", repeat=i):
		if int("".join(j))<=N and "7" in j and "5" in j and "3" in j:
			count += 1
print count

Submission status: Accepted

Solution code:
N = int(input())

S = [3, 5, 7]

now = N
l = 0

while now>0:
    l = l+1
    now = now//10    

for i in range(l-1):
    L = len(S)
    for j in range(L):
        tmp = S[j]*10+3
        S.append(tmp)
        tmp = S[j]*10+5
        S.append(tmp)
        tmp = S[j]*10+7
        S.append(tmp)
      
S2 = list(set(S))
S2.sort()
ans = 0
        
for i in S2:
    now = str(i)
    s3 = 0
    s5 = 0
    s7 = 0
    l2 = 0
    
    n = i
    
    while n>0:
        l2 = l2+1
        n = n//10
        
    for j in range(l2):
        if now[j]=='3':
            s3 = s3+1
        if now[j]=='5':
            s5 = s5+1
        if now[j]=='7':
            s7 = s7+1
    if s3*s5*s7>0 and s3+s5+s7==l2 and i<=N:
        ans = ans + 1
    elif i>N:
        break

print(ans)

Submission status: Accepted

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


def main():
    from itertools import product

    n = int(input())
    numbers = list()
    ans = 0

    for digit in range(1, 10):
        for i in list(product(['3', '5', '7'], repeat=digit)):
            numbers.append(''.join(map(str, list(i))))

    for number in numbers:
        if int(number) <= n:
            if '3' in number and '5' in number and '7' in number:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
def ok(x):
    v = []
    while x > 0:
        v.append(x % 10)
        x /= 10
    return len(set(v)) == 3

def f(x):
    if x > n:
        return 0
    res = sum(f(10*x+i) for i in [7,5,3])
    if ok(x):
        res += 1
    return res
print(f(0))

Submission status: Accepted

Solution code:
s = [["3", "5", "7"]]
for i in range(8):
  t = []
  for x in s[i]:
    t += [x+"3", x+"5", x+"7"]
  s += [t]

n = int(input())
c = 0
for l in s:
  for x in l:
    if len(set(list(x))) == 3 and int(x) <= n:
      c += 1
print(c)

Submission status: Accepted

Solution code:
from itertools import product

def f(n):
    return 3**n - 3*(1 + 2**n - 2)

s = input()
n = int(s)
m = len(s)

ans=0

if m>=4:
    for i in range(3,m):
        ans+=f(i)

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

print(ans)

Submission status: Accepted

Solution code:
def run(N):
    # 3, 5, 7のみの数値を全列挙
    targets = make357(N)
    cnt = 0
    for t in targets:
        if all(t.count(s) for s in '357'):
            cnt += 1
    return cnt


def make357(N):
    '''
    3, 5 ,7のみを含むN以下の数を全列挙
    ただし文字列として格納
    '''
    targets = []
    targets_i = ['3', '5', '7']  # i桁の357のみを含む数
    for _ in range(1, len(str(N))):
        tmp = []
        for s in '357':
            tmp += [t + s for t in targets_i if int(t + s) <= N]
        targets_i = tmp
        targets += targets_i
    return targets


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
count = 0
def f(s):
  global count
  if int(s) > n:
    return
  if all(s.count(i) > 0 for i in "357"):
    count += 1
  for i in "357":
    f(s+i)
f("0")    
print(count)

Submission status: Accepted

Solution code:
import math
N=input()

def f(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+=f(s+c)
    return Ans
    
print f("0")

Submission status: Accepted

Solution code:
import itertools
def calc_num(S,S_len):
  result = 0;
  l = [3,5,7];
  i = 3;
  while i <= S_len:
    for v in itertools.product(l,repeat=i):
      if int("".join(map(str,v))) <= S and list(set(v) & set(l)) == l:
        result = result + 1;
    i = i + 1;
  return result
  
S = list(map(int,input()));
S_len = len(S);
S = int("".join(map(str, S)));
result = calc_num(S,S_len);
print(result)

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:
import itertools
a = int(input())
ar = ["3","5","7"]
c = 0
for i in range(3,len(str(a))+1):
    for j in itertools.product(ar,repeat=i):
        if j.count("3") >= 1 and j.count("5") >= 1 and j.count("7") >= 1:
            if a >= int("".join(list(j))):
                c += 1
print(c)

Submission status: Accepted

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

print(dfs('0'))

Submission status: Accepted

Solution code:
import itertools

N = int(input())
d753 = ["3", "5", "7"]

c = 0
for i in range(1, 10):
	for d in itertools.product(d753, repeat = i):
		if d.count("3") >= 1 and d.count("5") >= 1 and d.count("7") >= 1:
			x = int("".join(d))
			if x <= N:
				c += 1

print(c)

Submission status: Accepted

Solution code:
n = int(input())
# Recursion!
def detector(str):
  # Stop the operation if the number is bigger than n.
  if int(str) > n:
    return 0
  else:
    count = 0
    # Add 7, 5, or 3 after the number. 
    # Eliminate numbers that do not consist of only 3, 5, and 7.
    for i in "753":
      count += detector(str+i)
    # Check if the number has all 3, 5, and 7.
    if "3" not in str or "5" not in str or "7" not in str:
      return count
    else:
      return count + 1
# Start from 0 and do the operation until the number exceeds n.
print(detector("0"))

Submission status: Accepted

Solution code:
def solve(s):
    if int(s) > N:
        return 0

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

d_in = lambda: int(stdin.readline())  # N = d_in()

cand = [0, 3, 5, 7]
N = d_in()


def check_count(count):
    if count[3] > 0 and count[5] > 0 and count[7] > 0:
        return True
    else:
        return False


def search(flag, nonzero, str_n, count):
    """
    flag : 現在の値がNと等しいか小さいか

    nonzero : 現在の値が0か否か

    str_n : 現在より小さい方の各桁を文字列として持つリスト

    count : {7: flag1, 5: flag2, 3: flag3}
    """
    if len(str_n) == 0:
        if check_count(count):
            return 1
        else:
            return 0
    elif check_count(count) and (not flag):
        return 3**(len(str_n))
    elif not flag:
        ans = 0
        for i in cand:
            if nonzero and i == 0:
                continue
            next_count = count.copy()
            next_count[i] += 1
            zeroflag = nonzero or (i != 0)
            ans += search(False, zeroflag, str_n[1:], next_count)
        return ans
    else:
        next_n = int(str_n[0])
        ans = 0
        for i in cand:
            if nonzero and i == 0:
                continue
            next_count = count.copy()
            if i > next_n:
                break
            elif i == 0:
                zeroflag = nonzero
                ans += search(False, zeroflag, str_n[1:], next_count)
            elif i == next_n:
                next_count[i] += 1
                ans += search(True, True, str_n[1:], next_count)
            else:
                next_count[i] += 1
                ans += search(False, True, str_n[1:], next_count)
        return ans


str_N = list(str(N))
cand_count = {0: 0, 3: 0, 5: 0, 7: 0}
print(search(True, False, str_N, cand_count))

Submission status: Accepted

Solution code:
N = int(input())
import itertools

count = 0
data = [3,5,7]
for i in range(3, len(str(N))+1):
    l = list(itertools.product(data, repeat=i))
    for j in range(len(l)):
        n = 0
        if 3 in l[j] and 5 in l[j] and 7 in l[j]:
            for keta in range(i-1,-1,-1):
                n += 10**keta * l[j][keta]
            if n <= N:
                count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

elements = '753'

def dfs(S):
    if int(S) > N:
        return 0
    ans = 1 if all(S.count(element) for element in elements) else 0
    for element in elements:
        ans += dfs(S+element)
    return ans

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0
    ret = 0
    for c in '753':
        ret += dfs(s+c)
    if '3' not in s or '5' not in s or '7' not in s:
        return ret
    return ret+1


print(dfs('0'))

Submission status: Accepted

Solution code:
import math

def count(target, digits, previous, candidates=[3,5,7]):
    if digits==0:
        nstr="{}".format(previous)
        chars=[int(c) for c in nstr]
        chars=set(chars)
        #print("#debug candidate={}".format(previous))
        for c in candidates:
            if not c in chars:
                #print("#debug {} not in {}".format(c,chars))
                return 0
#        print("#debug ok {}".format(previous))
        return 1
    #print("#debug {} {} {}".format(target,digits,previous))
    base = 10**(digits-1)
    ncases = 0
    for c in candidates:
        candidate = base*c + previous
        if candidate>target:
            continue
        ncases = ncases + count(target, digits-1, candidate) 
    return ncases
        
n=input()
ni=int(n)
ndigits=len(n)

ncases=0
#ndigits-1桁の場合3,5,7を自由においてもnを超えることはない
#3,5,7をつかってできる3桁以上ndigits-1桁以下の整数の個数を数える
#多項式の係数と同じ形式
#9!=362880なのでintに収まる
for p in range(3,ndigits):
    for i in range(1,p-1):
        for j in range(1,p-i):
#            print("{}, {}".format(i,j))
            ncases=ncases+int(math.factorial(p)/math.factorial(i)/math.factorial(j)/math.factorial(p-i-j))

#print("#debug reduced {}".format(ncases))
ncases=ncases+count(ni,ndigits,0)
print(ncases)

Submission status: Accepted

Solution code:
A = []
def svt(now, count):
    A.append(now)
    if count > 10:
        return
    else:
        svt(now * 10 + 7, count + 1)
        svt(now * 10 + 5, count + 1)
        svt(now * 10 + 3, count + 1)

svt(3, 1)
svt(5, 1)
svt(7, 1)

A.sort()
N = int(input())
ans = 0
for i in A:
    j = str(i)
    a = 0
    b = 0
    c = 0
    for k in range(len(j)):
        if j[k] == "3":
            a = 1
        elif j[k] == "5":
            b = 1
        elif j[k] == "7":
            c = 1
    if a == 1 and b == 1 and c == 1 and i <= N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
ans = 0
 
def dfs(s, n):
    global ans

    if s != "" and int(s) > n:
        return
    elif "3" in s and "5" in s and "7" in s:
        ans += 1

    for i in "753":
        dfs(s+i, n)

n = int(input())
dfs("", n)
print (ans)

Submission status: Accepted

Solution code:
from itertools import product
from bisect import bisect_left,bisect_right
#pre processing
st = '753'
ls = []
for i in range(3,10):
	s = list(product(st,repeat = i))
	for i in s:
		zz = ''.join(list(i))
		ls.append(zz)

arr = []
for i in ls:
	if '7' in i and '5' in i and '3' in i:
		arr.append(int(i))
arr.sort()
n = input()
print bisect_right(arr,n)

Submission status: Accepted

Solution code:
S = input()
N = int(S)


def count753(s):
    is753 = "7" in s and "5" in s and "3" in s
    if len(s) == len(S):
        return 1 if int(s) <= N and is753 else 0
    return int(is753) + count753(s + "7") + count753(s + "5") + count753(s + "3")


print(count753("7") + count753("5") + count753("3"))

Submission status: Accepted

Solution code:
from bisect import bisect
T = list()
def make_list(i):
    number = ''
    n_4 = i
    while n_4 > 0:
        number = str(n_4 % 4) + number
        n_4 = n_4//4
    return number 
for n in range (0,3*10**5):
    number = make_list(n)
    if (('0' in number) or ('1' not in number) or ('2' not in number) or ('3' not in number)):
        continue
    number = number.replace('3','7')
    number = number.replace('2','5')
    number = number.replace('1','3')
    T.append(int(number))
N = int(input())
X = bisect(T,N)
print(X)

Submission status: Accepted

Solution code:
N = int(input())


def solve(x, t, f, s):
    if x > N:
        return 0

    res = 0
    if t and f and s:
        res += 1

    res += solve(x*10+3, t+1, f, s)
    res += solve(x*10+5, t, f+1, s)
    res += solve(x*10+7, t, f, s+1)

    return res


def main():
    print(solve(0, 0, 0, 0))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

print(cnt('0'))

Submission status: Accepted

Solution code:
n =int(input())

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

Submission status: Accepted

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

def make753(s):
    global count
    if int(s) > n:
        return 0
    if all(s.count(i) > 0 for i in '753'):
        count += 1
    for i in '753':
        make753(s + i)
    return count
           
print(make753('0'))

Submission status: Accepted

Solution code:
from itertools import product
element = [3,5,7]

N = int(input())
ans = 0
for i in range(3, len(str(N)) + 1) :
    L = product(element, repeat=i)
    for candidate in L :
        if ((3 not in candidate) or (5 not in candidate) or (7 not in candidate)) :
            continue
        l = int("".join(list(map(str,candidate))))
        if l <= N :
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from bisect import  bisect

def convert(number) :
    if number == 0 :
        out = "0"
    else :
        out = ""
    while number > 0 :
        surplus = (number % 4)
        out = str(surplus) + out
        number //= 4
    return out

def seven_five_three(string) :
    string = string.replace("3","7").replace("2","5").replace("1","3")
    return string

L = []
for i in range(3*10**5) :
    l = convert(i)
    l = seven_five_three(l)
    if (("0" in l) or ("3" not in l) or ("5" not in l) or ("7" not in l)) :
        continue
    l = int(l)
    L.append(l)

N = int(input())
ans = bisect(L,N)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def check(number):
    string = str(number)
    if("3" in string and "5" in string and "7" in string):
        if(number <= N):
            return 1
    return 0

def make_root_three(num):
    ans = 0
    i = 0
    while(num // 3):
        ans += (num % 3) * (10 ** i)
        num = num // 3
        i += 1
    ans += num * (10 ** i)
    return ans

def make_number_from_seed(seed, l):
    ans = 0
    string = str(seed).zfill(l)
    for i in range(l):
        ans += candidates[int(string[i])] * (10 ** i)
    return ans

N = int(input().strip())
length = int(np.log10(N)) + 1

candidates = [3, 5, 7]
ans = 0

for l in range(3, length + 1):
    for i in range(3**l):
        seed = make_root_three(i)
        number = make_number_from_seed(seed, l)
        ans += check(number)
    
print(ans)

Submission status: Accepted

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

def make753(s):
    global count
    if int(s) > n:
        return 0
    if all(s.count(i) > 0 for i in '753'):
        count += 1
    for i in '753':
        make753(s + i)
    return count
        
print(make753('0'))

Submission status: Accepted

Solution code:

N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
ans = 0
for l in range(1, 10):
    for p in product("357", repeat=l):
        v = "".join(p)
        if "3" in v and "5" in v and "7" in v and int(v) <= N:
            ans += 1
            continue
        elif int(v) > N :
            break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def recursive(s):
    if int(s) > n:
        return 0
    ret = 0
    if s.count('3')>0 and s.count('5')>0 and s.count('7')>0:
        ret = 1
    for c in '753':
        ret += recursive(s+c)
    return ret           

print(recursive('0'))

Submission status: Accepted

Solution code:
def change_ten_to_kisu(num, kisu):      # 10進数をkisu進数に変換 (int, int) => int
    r = 0
    syo = num
    count = 0
    while syo >= kisu:
        r += (syo % kisu) * 10 ** count
        syo = syo // kisu
        count += 1
    return r + syo * 10 ** count

def change_kisu_to_ten(num, kisu):      # kisu進数を10進数に変換 (int, int) => int
    n = str(num)
    r = 0
    for i in range(len(n)):
        r += int(n[-i - 1]) * kisu ** i
        # print(r, int(n[-i - 1]), kisu ** i)
    return r

def plus(num):                   # 3, 5, 7のみを使用しnumより大きい数を返す
    change = {"3" : "0", "5" : "1", "7" : "2"}
    change_r = {"0" : "3", "1" : "5", "2" : "7"}
    t = ""
    for i in str(num):
        t += change[i]
    r = change_ten_to_kisu(change_kisu_to_ten(int(t), 3) + 1, 3)
    if len(t) < len(str(r)):
        r = "0" + str(r)[1:]
    elif len(t) > len(str(r)):
        r = "0" * (len(t) - len(str(r))) + str(r)
    t = ""
    for i in str(r):
        t += change_r[i]
    return int(t)

N = int(input())

i = 3
count = 0
while i <= N:
    if "3" in str(i) and "5" in str(i) and "7" in str(i):
        # print(i)
        count += 1
    i = plus(i)
print(count)

Submission status: Accepted

Solution code:
S = input()
threeS=""
flag=0
count=0
for s in S:
    if flag == 1:
        threeS = threeS + "3"
    elif s > "7":
        threeS = threeS + "3"
        flag=1
    elif s == "7":
        threeS = threeS + "3"
    elif s > "5":
        threeS = threeS + "2"
        flag=1
    elif s == "5":
        threeS = threeS + "2"
    elif s > "3":
        threeS = threeS + "1"
        flag=1
    elif s =="3":
        threeS = threeS + "1"
    else:
        if threeS == "":
            threeS = threeS + "0"
        else:
            threeS = threeS[0:-1] + str(max(0,int(threeS[-1:])-1))
            threeS = threeS + "3"
        flag=1

x=str(111)
count = 0

def add(s):
    if s == "":
        return "1"
    s = str( int(s)+1 )
    if s[-1:] == "4":
        s = add(s[:-1]) + "1"
    return s

while int(x) <= int(threeS):
    if "1" in x:
        if "2" in x:
            if "3" in x:
                count += 1
    x = add(x)

print(count)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())
num = ['3', '5', '7']
array = ['']
len_array = [0, 0, len(array)]
for i in range(len(str(N))):
    array.extend(array[len_array[1]:] * 3)
    len_array = [len_array[1], len_array[2], len(array)]
    for j in range(len_array[1], len_array[2]):
        diff_len = len_array[2] - len_array[1]
        for k in range(3):
            if k * diff_len // 3 + len_array[1] <= j < (k + 1) * diff_len // 3 + len_array[1]:
                array[j] += num[k]
array = [int(array[i]) for i in range(len(array)) if set(num) <= set(array[i])]
array = list(filter(lambda i: i <= N, array))
print(len(array))

Submission status: Accepted

Solution code:
import re

N = int(input())

numList = []
def plusNum(num, N):
    if num > N:
        return
    numList.append(num)
    for i in [3, 5, 7]:
        plusNum(int(str(num) + str(i)), N)

for num in [3, 5, 7]:
    plusNum(num, N)

ans = 0
for num in numList:
    num_str = str(num)
    count_3 = 0
    count_5 = 0
    count_7 = 0
    for i in range(len(num_str)):
        if num_str[i] == "3":
            count_3 += 1
        elif num_str[i] == "5":
            count_5 += 1
        elif num_str[i] == "7":
            count_7 += 1
        if count_3 >= 1 and count_5 >= 1 and count_7 >= 1:
            ans += 1
            break

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
    for c in "753":
        ret += dfs(s+c)
    return ret
print(dfs("0"))

Submission status: Accepted

Solution code:
N=int(input())

def keta(x, k):
    if x%10==x:
        return k
    else:
        y=x//10
        k+=1
        return keta(y,k)

ls_375_tmp=[]
def func(a, n, keta):
    if n==keta:
        return
    for num in ['3', '5', '7']:
        ls_375_tmp.append(int(num+a))
        func(num+a, n+1,keta)

keta_N=keta(N,1)
func('', 0, keta_N)

ct=0
for i in ls_375_tmp:
    if all(x in str(i) for x in ['3', '5', '7']) and i<=N:
        ct+=1
print(ct)

Submission status: Accepted

Solution code:
N = int(input())

ret = 0


def solve(seven=False, five=False, three=False, num=0):
    global ret
    if num <= N:
        if seven and five and three:
            ret += 1
        solve(True, five, three, num * 10 + 7)
        solve(seven, True, three, num * 10 + 5)
        solve(seven, five, True, num * 10 + 3)
    else:
        return


solve()
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
def rec(s):
    if int(s) > n:
        return 0
    ans = 0
    if all(s.count(c) > 0 for c in "753"):
        ans = 1
    for c in "753":
        ans += rec(s+c)
    return ans
print(rec("0"))

Submission status: Accepted

Solution code:
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    if (s.count('3')>0)and(s.count('5')>0)and(s.count('7')>0):
        ans = 1
    else:
        ans = 0
    for c in '753':
        ans += dfs(s + c)
    return ans
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())

def f(s):
    ans = 0
    if (int)(s) > n:
        return 0
    for c in '753':
        num = (str)(s+c)
        if (int)(num) <= n:
            if num.count('3')and num.count('5') and num.count('7'):
                ans += 1
            ans += f(num)
    return ans
print(f('0'))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
dig = len(str(N))
ans = 0
for i in range(3,dig+1):
    for a in product('357',repeat=i):
        num = int("".join(a))
        if num > N:
            continue
        s = set(a)
        if not '3' in s:
            continue
        if not '5' in s:
            continue
        if not '7' in s:
            continue
        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
	for c in '753':
		ret += dfs(s + c)
	return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
N=int(input())
count=0
def saiki(word):
    nums=['3','5','7']
    global count
    ans=0
    if(N==word):
        saiki(nums[0])
        saiki(nums[1])
        saiki(nums[2])
    elif(int(word)>N):
        return
    else:
        if '3' in word and '5' in word and '7' in word:
            count+=1
        saiki(word+nums[0])
        saiki(word+nums[1])
        saiki(word+nums[2])
        return
saiki(N)
print(count)

Submission status: Accepted

Solution code:

N = int(input())
# 再帰関数
def dfs(s):
  if int(s) > N:
    return 0
# ７５３が含まれる数列を回収
  if(all(s.count(c) for c in '753')):
    ret = 1
  else:
  	ret = 0
# 条件にあう数列を抜き出している
  for c in '753':
    ret += dfs(s + c)
  return ret
# ’０’からスタート
print(dfs('0'))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)
N = int(input())
svt = []

def dfs(num):
    if num>1000000000:
        return
    #elif num<100:
    #    return
    else:
        svt.append(int(str(num)+'3'))
        dfs(int(str(num)+'3'))
        svt.append(int(str(num)+'5'))
        dfs(int(str(num)+'5'))
        svt.append(int(str(num)+'7'))
        dfs(int(str(num)+'7'))

def check753(num):
    exist3 = False
    exist5 = False
    exist7 = False
    s = str(num)
    for c in s:
        if c=='3':
            exist3 = True
        elif c=='5':
            exist5 = True
        elif c=='7':
            exist7 = True
    if exist3 and exist5 and exist7:
        return True
    else:
        return False


dfs(0)
svt = sorted(svt)
svt = svt[12:]
#print(svt)
count = 0
for i in range(len(svt)):
    if svt[i]>N:
        break
    if check753(svt[i]):
        count += 1
print(count)

Submission status: Accepted

Solution code:
import itertools
N = int(input())

# 3~9桁まで(3^9は十分探索可能)
num = 0
for m in range(3,10):
    for v in itertools.product(['3','5','7'], repeat=m):
        if '3' in v and '5' in v and '7' in v and int(''.join(v)) <= N:
            num += 1

print(num)