Problem:


Score : 300 points

Problem Statement

You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?

Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

Sample Input 1

575

Sample Output 1

4

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

Sample Input 2

3600

Sample Output 2

13

There are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.

Sample Input 3

999999999

Sample Output 3

26484



Sample input:
575


Sample output:
4

Submission status: Accepted

Solution code:
N = int(input())

def 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 = input()
L = len(N)
NUM = int(N)

count = 0
for l in range(1, L):
        count += 3**l - 3*2**l + 3
q = '3'*L
while True:
        if int(q) > NUM:
                break
        if q.count('3') > 0 and q.count('5') > 0 and q.count('7') > 0:
                count += 1
        if q == '7'*(L-2) + '5' + '3':
                break
        for i in range(1, L+1):
                k = q[-i]
                if k == '3':
                        next = q[:-i] + '5' + '3'*(i-1)
                        break
                elif k == '5':
                        next = q[:-i] + '7' + '3'*(i-1)
                        break
        q = next

print(count)

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

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
    if int (s) > N:
        return 0
    ret = 1 if all(s.count(c) > 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 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
N = int(input())
n = len(str(N))
lst = [3, 5, 7]

def calc(count, tmp):
    ans = 0
    if count >= 9:
        return 0
    for i in lst:
        tmp += i * (10 ** count)
        # print (i, tmp)
        if tmp <= N:
            # print (tmp)
            if  '7' in str(tmp) and '5' in str(tmp) and '3' in str(tmp):
                ans += 1
        ans += calc(count + 1 ,tmp)
        tmp -= i * (10 ** count)
    return ans

ans = calc(0, 0)
print (ans)

Submission status: Accepted

Solution code:
def sub753(K, lst):
    if K == 1:
        return ['3', '5', '7']
    ans = [pre + suf for suf in sub753(K - 1, lst) for pre in '357']
    lst.extend(ans)
    return ans


N = int(input())

lst = list()
sub753(10, lst)

cnt = 0
for num in lst:
    if '3' in num and '5' in num and '7' in num and int(num) <= N:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def ac(s, t, int3, int5, int7):
    if s == "":
        return ac(s + "3", t, int3 + 1, int5, int7) \
               + ac(s + "5", t, int3, int5+1, int7) \
               + ac(s + "7", t, int3, int5, int7+1)
    elif int(s) <= t:
        if int3 != 0 and int5 != 0 and int7 != 0:
            return 1 \
                   + ac(s + "3", t, int3 + 1, int5, int7) \
                   + ac(s + "5", t, int3, int5+1, int7) \
                   + ac(s + "7", t, int3, int5, int7+1)
        else:
            return 0 \
                   + ac(s + "3", t, int3 + 1, int5, int7) \
                   + ac(s + "5", t, int3, int5 + 1, int7) \
                   + ac(s + "7", t, int3, int5, int7 + 1)
    else:
        return 0


a = int(input())
print(ac("", a, 0, 0, 0))

Submission status: Accepted

Solution code:
num753 = ['7', '5', '3']
N = int(input())
cnt = 0
for i in range(3, len(str(N))+1):
	for j in range(0, 3**i):
		m = j
		exists = [False, False, False]
		num = ''
		for k in range(0, i):
			num = num + num753[m%3]
			exists[m%3] = True
			m //= 3
		if False not in exists and int(num) <= N:
			cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = input()

def dfs(m):
    ans = 0
    if len(set(m)) == 3 and int(m) <= int(N):
        ans += 1

    if len(m) < len(N):
        for c in ['3', '5', '7']:
            ans += dfs(m + c)

    return ans

print(dfs(""))

Submission status: Accepted

Solution code:
N = int(input())

def search(keta, num):
  if keta == 0:
    if '0' in str(int(num)):
      return 0
    elif '3' in num and '5' in num and '7' in num:
      if int(num) <= N:
        return 1
      else:
        return 0
    else:
      return 0
  else:
    return search(keta-1, num + '0') + search(keta-1, num + '3') + search(keta-1, num + '5') + search(keta-1, num + '7')

keta = len(str(N))

ans = search(keta, '')
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def search(s) :
    if int(s) > N :
        return 0
    ret = 1 if all(s.count(i) > 0 for i in ['7', '5', '3']) else 0  # 753数
    for c in ['7', '5', '3'] :
        ret += search(s + c)
    return ret

ans = search('0')

print(ans)

Submission status: Accepted

Solution code:
#Coding: Utf-8

N=int(input())

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

print(check('0'))

Submission status: Accepted

Solution code:
n = int(raw_input())

def count(sc):
    c3 = 0
    c5 = 0
    c7 = 0
    for c in sc:
        if c == "3":
            c3 += 1
        elif c == "5":
            c5 += 1
        elif c == "7":
            c7 += 1
        else:
            raise ValueError("error!")
    return c3 > 0 and c5 > 0 and c7 > 0
            

def up(tsc):
    res = ['0']*(len(tsc)+1)
    done = False
    i = len(tsc) - 1
    while not done and i >= -1:
        if tsc[i] == '7':
            carry = True
            res[i+1] = '3'
        elif tsc[i] == '5':
            res[i+1] = "7"
            done = True
        elif tsc[i] == '3':
            res[i+1] = "5"
            done = True
        elif i == -1:
            res[i+1] == '3'
            done = True
        i -= 1
    for i in range(i, -1, -1):
        res[i+1] = tsc[i]
    if res[0] == "0":
        return "".join(res[1:])
    else:
        return "".join(res)
        
def solve(n):
    tsc = "357"
    res = 0
    while int(tsc) <= n:
        if count(tsc):
            res += 1
        tsc = up(tsc)
    return res
print solve(n)

Submission status: Accepted

Solution code:
n = int(input())

def solve(now,seven,five,three):
    if now > n:
        return 0
    if min(seven,five,three) != 0:
        cnt = 1
    else:
        cnt = 0
    cnt += solve(now*10+3,seven,five,three+1)
    cnt += solve(now*10+5,seven,five+1,three)
    cnt += solve(now*10+7,seven+1,five,three)

    return cnt
print(solve(0,0,0,0))

Submission status: Accepted

Solution code:
def check753(s):
    global n
    if int(s) > n:
        return 0
    else:
        cnt = 1 if all(s.count(c) > 0 for c in '753') else 0
        for c in '753':
            cnt += check753(s+c)
        return cnt

if __name__ == "__main__":
    n = int(input())
    print(check753('0'))

Submission status: Accepted

Solution code:
import numpy as np

n = input()
r = len(n)
n = int(n)
kouho = []
pre = [""]

for i in range(r):
    pro = []
    for temp in pre:
        kouho.append(temp+"3")
        kouho.append(temp+"5")
        kouho.append(temp+"7")
        pro.append(temp+"3")
        pro.append(temp+"5")
        pro.append(temp+"7")
    pre = pro

def ctit(s):
    a = 0
    b = 0
    d = 0
    for c in s:
        if c == "3":
            a += 1
        elif c == "5":
            b += 1
        else:
            d += 1
    if a > 0 and b > 0 and d > 0:
        return True
    else:
        return False

ans = 0
for temp in kouho:
    if int(temp) <= n:
        if ctit(temp):
            ans += 1

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

Submission status: Accepted

Solution code:
N = int(input())
stack = [3, 5, 7]
counter = 0
def check753(i):
	s = str(i)
	
	if s.count('3') >= 1 and s.count('5') >= 1 and s.count('7') >= 1:
		return 1
	else:
		return 0

while stack:
	now_node = stack.pop()
	for i in [3, 5, 7]:
		next_node = now_node * 10 + i
		if next_node <= N:
			counter += check753(next_node)
			stack.append(next_node)

print(counter)

Submission status: Accepted

Solution code:
N=int(input())

answer=0
def dfs(d):
  global answer
  if d>N:
    return
  
  d_str=str(d)
  if "3" in d_str and "5" in d_str and "7" in d_str:
    #print(d)
    answer+=1
  
  for dd in [3,5,7]:
    dfs(10*d+dd)
    
dfs(0)
print(answer)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
#     print(s)
    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'))#avoid line4's contition

Submission status: Accepted

Solution code:
def rec(s):
    if not (s == "") and int(s) > n:
        return 0
    res = 0
    if all(c in s for c in '753'):
        res += 1
    for c in '753':
        res += rec(s + c)
    return res

n = int(input())
print(rec(""))

Submission status: Accepted

Solution code:
import itertools
s = input()
cnt = 0
# 桁数
digits = len(s)
# 桁数 までのカウントをあらかじめいれておく
cntl = [0, 6, 42, 192, 732, 2538, 8334]
# 七五三 number
number = ["3", "5", "7"]
if digits < 3:
    print(0)
    exit()
for i in itertools.product(number, repeat=digits):
    if "3" in i and "5" in i and "7" in i:
        if int(''.join(i)) <= int(s):
            cnt += 1
print(cnt + cntl[digits - 3])

Submission status: Accepted

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

import itertools
import bisect

n = int(input())
l = len(str(n))
ans = []
for i in range(3,l+1):
    for x in itertools.product("357",repeat = i):
        s = ''
        if x.count('7')*x.count('5')*x.count('3') == 0:
            continue
        for j in x:
            s += j
        ans.append(int(s))
ans.sort()
print(bisect.bisect_right(ans,n))

Submission status: Accepted

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

n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    for c in '753':
        if s.count(c) > 0:
            continue
        else:#sが753数でないなら
            ret = 0
            break
    else:#sが753数なら
        ret = 1
    for c in '753':
        ret += dfs(s+c)#sに7,5,3を追加
    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
n=int(input())
l=[]
import itertools
for i in range(3,10):
    for x in itertools.product("357",repeat=i):
        p=""
        if x.count("7")*x.count("5")*x.count("3")==0:
            continue
        for j in x:
            p+=j
        l.append(int(p))
l.sort()

import bisect
ans=bisect.bisect_right(l,n) 
print(ans)

Submission status: Accepted

Solution code:
def rec(s):
    """引数末尾に753を付け加えてできる753数
    753以外の数が現れないように文字を加えているので、
    ・すべて一回以上出たら753数に加算
    ・Nを超えたらreturn 0
    させればよい"""
    # base case
    if int(s) > n:
        return 0

    res = 0
    if all(c in s for c in '753'):
        res += 1

    # 再帰ステップ
    for c in '753':
        res += rec(s + c)
    return res


n = int(input())
print(rec('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:
# https://atcoder.jp/contests/abc114/submissions/6262572

from itertools import product
N = int(input())
ans = 0
for i in range(3,10):
    for s in product(["3","5","7"],repeat=i):
        if int("".join(s)) <= N and "3" in s and "5" in s and "7" in s:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc114/submissions/6262572

from itertools import product
N = input()
n = int(N)
ans = 0
for i in range(3,10):
    for s in product(["3","5","7"],repeat=i):
        if int("".join(s)) <= n and "3" in s and "5" in s and "7" in s:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc114/submissions/6262572

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc114/submissions/6262572

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

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
memo = {i:1 for i in [357, 375, 537, 573, 735, 753]}
ans = 0
queue = deque()
mod = [10**i for i in range(10)]
for key in memo.keys():
  if key <= N:
    ans += 1
    queue.append(key)
while queue:
    key = queue.popleft()
    len_key = len(str(key))
    for i in range(len_key):
        for j in [3,5,7]:
            tmp = (key // mod[i]) * mod[i+1] + j * mod[i] + key % mod[i]
            if tmp not in memo and tmp <= N:
                ans += 1
                memo[tmp] = 1
                queue.append(tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

a = input()
b = ["3", "5", "7"]
d = 0
for i in range(1, len(a)+1):
    for j in itertools.product(b, repeat=i):
        c = ""
        for k in range(len(j)):
            c += j[k]
        if int(c) <= int(a):
            if "3" in c and "5" in c and "7" in c:
                d += 1
print(d)

Submission status: Accepted

Solution code:
from functools import lru_cache
n = int(input())

def variety(n, arr) :
    ms = set()
    for a in range(n) :
        ms |= count(a+1, arr)
    return(ms)

@lru_cache(maxsize=36)
def count(n, arr) :
    if n == 1 :
        return set(arr)
    else :
        ms = set()
        for a in arr :
            for m in count(n-1, arr) :
                m2 = int(str(a)+str(m))
                ms.add(m2)
        return ms

mylist = list(variety(9, (7, 5, 3))\
            - variety(9, (7, 5))\
            - variety(9, (5, 3))\
            - variety(9, (3, 7)))

print(len([1 for i in mylist if i <= n]))

Submission status: Accepted

Solution code:
N=input()

if len(N)<3:
    print(0)
else:
    arr=set([357, 375, 537, 573, 735, 753])
    for i in range(len(N)-3):
        new=set()
        for num in arr:
            for j in range(len(str(num))+1):
                n=str(num)[:j]+'3'+str(num)[j:]
                new.add(int(n))
                n=str(num)[:j]+'5'+str(num)[j:]
                new.add(int(n))
                n=str(num)[:j]+'7'+str(num)[j:]
                new.add(int(n))
        arr |= new

    arr=list(arr)
    arr.sort()
    cnt=0
    for i in range(len(arr)):
        if arr[i]<=int(N):
            cnt+=1
        else:
            break
    print(cnt)

Submission status: Accepted

Solution code:
"""
753の数
"""

import sys
sys.setrecursionlimit(100000)
N = int(input())
# seen = [False] * N
"""
1. Gを予め作って探索するパターン
2. Gを作りながら探索するパターン
"""
cnt = 0
def dfs(v):
    global cnt
    # vを訪問済みにする
    # seen[v] = True
    num = "753"
    #グラフ中の次のVについて
    for n in num:
        next_v = v + n
        # 探索打ち切り条件->
        # すでに探索済み or なにかの終了条件に引掛かる
        if int(next_v) > N: continue
        # 見られていない場合、再帰的に探索
        dfs(next_v)
        if "3" in next_v and "5" in next_v and "7" in next_v:
            cnt += 1

dfs("")
print(cnt)

Submission status: Accepted

Solution code:
def make_num(n):
    if int(n) > N:
        return 0
    elif "3" in n and "5" in n and "7" in n:
        ans = 1
    else:
        ans = 0
    for i in "357":
        ans += make_num(n+i)
    return ans
N = int(input())
print(make_num("0"))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ok = True
    ret = 0
    for c in "753":
        if s.count(c) < 1:
            ok = False
            break
    if ok:
        ret = 1
    for c in "753":
        ret += dfs(s+c)
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
# editorialを参考にした
N = int(input())
ans = 0

def count(s):
    global ans
    if int(s) > N:
        return 0
    elif s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
        ans += 1

    for j in "357":
        count(s+j)


count("0")
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Nstr = str(N)

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())

cnt = 0
nums = ''

def dfs(nums):
    global cnt
    
    if len(nums) >= 10:
        return
        
    k = list(nums)
    k = set(nums)

    if len(nums) >= 1:
        if int(nums) <= N and len(k) >= 3:
            cnt += 1
    
    dfs(nums + '3')
    dfs(nums + '5')
    dfs(nums + '7')

    return

dfs(nums)

print(cnt)

Submission status: Accepted

Solution code:
def dfs(s,num):
    if int(s)>num:
        return 0
    if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
        ret=1
    else:
        ret=0
    for i in "753":
        ret+=dfs(s+i,num)
    return ret
n=int(input())
print(dfs('0',n))

Submission status: Accepted

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


c = 0
num = 0
def check(n):
	strn = str(n)
	l = [0, 0, 0]
	for c in strn:
		if c == '3':
			l[0] = 1
		elif c == '5':
			l[1] = 1
		elif c == '7':
			l[2] = 1
	return all(l) or False

def gen(n):
	global c
	# print(n)
	if n > num:
		return
	if check(n):
		# print(n)
		c += 1
	for i in [3, 5, 7]:
		k = 10 * n + i
		gen(k)

def main():
	global num
	num = int(input().strip())
	gen(0)
	print(c)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N = input()
 
ans = 0
def dfs(m):
    global ans
    if len(set(m))==3 and int(m)<=int(N):
        ans+=1
        
    if len(m)<len(N):
        for i in "357":
            dfs(m+i)
dfs("")
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# c-abc114.py
import itertools
# input
a = input()
N = int(a)
e = len(a)
c = 0
for i in range(3, e):
    o = itertools.product(['3', '5', '7'], repeat=i)
    for j in o:
        if all(j.count(k) > 0 for k in '357') == True:
            c += 1
l = itertools.product(['3', '5', '7'], repeat=e)
for m in l:
    if all(m.count(k) > 0 for k in '357') == True and int(''.join(m)) <= N:
        c += 1
print(c)

Submission status: Accepted

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

def is_753(n):
	s = str(n)
	f = [0,0,0]
	for c in s:
		if c == '3':
			f[0] = 1
		elif c == '5':
			f[1] = 1
		elif c == '7':
			f[2] = 1
	if all(f):
		return True
	else:
		return False

N = 0
c = 0
def gen(n):
	global c
	for i in [3,5,7]:
		k = 10 * n + i
		# print(k)
		if k > N:
			return
		if is_753(k):
			c += 1
			# print(k)
		gen(k)

def main():
	global N
	s = input().strip()
	N = int(s)
	n = len(s)

	gen(0)
	print(c)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N = input()

ans = 0
def dfs(m):
    global ans
    if len(set(m)) == 3 and int(m) <= int(N):
        #print(m, ans)
        ans += 1

    if len(m) < len(N):
        for c in "357":
            dfs(m+c)

dfs("")
print(ans)

Submission status: Accepted

Solution code:
n = input()
count357 = ["3", "5", "7"]
i = 0
while int(count357[-1]) <= int(n):
    for j in range(3):
        count357.append(str(int(count357[i])*10 + int(count357[j])))
        if int(count357[-1]) > int(n):
            break
    i += 1
count357.pop(-1)
count = 0
for i in range(len(count357)):
    count += 1 if "3" in count357[i] and "5" in count357[i] and "7" in count357[i] else 0

print(count)

Submission status: Accepted

Solution code:
n = input()
a = "357"
count357 = ["3", "5", "7"]
i = 0
while int(count357[-1]) <= int(n):
    for j in range(3):
        count357.append(str(int(count357[i])*10 + int(count357[j])))
        if int(count357[-1]) > int(n):
            break
    i += 1
count357.pop(-1)
count = 0
for i in range(len(count357)):
    count += 1 if "3" in count357[i] and "5" in count357[i] and "7" in count357[i] else 0

print(count)

Submission status: Accepted

Solution code:
n = input()
a = "357"
count357 = ["3", "5", "7"]
i = 0
count = 0
while int(count357[-1]) <= int(n):
    for j in range(3):
        count357.append(str(int(count357[i])*10 + int(count357[j])))
        if int(count357[-1]) > int(n):
            break
    i += 1
count357.pop(-1)
for i in range(len(count357)):
    if "3" in count357[i] and "5" in count357[i] and "7" in count357[i]:
        count += 1
print(count)

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

def f(x):
    if int(x) > n:
        return 0
    if all([x.count(a) > 0 for a in '753']):
        num = 1
    else:
        num = 0
    for a in '753':
        num += f(x + a)
    return num

print(f('0'))

Submission status: Accepted

Solution code:
from collections import deque
X = int(input())
# その時の数字と、3,5,7が今までに含まれていたか
q = deque([""])
q_is3 = deque([0])
q_is5 = deque([0])
q_is7 = deque([0])
N = "357"
ans = 0
while q:
    num = q.popleft()
    is3 = q_is3.popleft()
    is5 = q_is5.popleft()
    is7 = q_is7.popleft()
    for n in N:
        next_v = num + n
        if int(next_v) > X: continue
        else:
            next_is3 = is3 or n == "3"
            next_is5 = is5 or n == "5"
            next_is7 = is7 or n == "7"
            q.append(next_v)
            q_is3.append(next_is3)
            q_is5.append(next_is5)
            q_is7.append(next_is7)
            if next_is3 and next_is5 and next_is7:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
X = int(input())
q = deque([""])
N = "357"
ans = 0
while q:
    num = q.popleft()
    for n in N:
        next_v = num + n
        if int(next_v) > X: continue
        else:
            q.append(next_v)
            if "3" in next_v and "5" in next_v and "7" in next_v:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

cnt = 0
num = ""
X = int(input())
def dfs(num,is3,is5,is7):
    global cnt
    if is3 and is5 and is7:
        cnt += 1 
    N = "357"
    for n in N:
        next_v = num + n
        if int(num+n) > X: continue #終了条件
        # 次の状態遷移
        dfs(next_v,is3 or n=="3",is5 or n=="5",is7 or n=="7")

dfs("0",0,0,0)
print(cnt)

Submission status: Accepted

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


def f755(d, n, t, f, s):
    if NI < n:
        return 0
    if d < 0 and (t and f and s):
        return 1
    r = 0
    if n == 0 and d > 0:
        r += f755(d - 1, n, t, f, s)
    if d >= 0:
        r += f755(d - 1, n + 3 * (10 ** d), t or 1, f, s)
        r += f755(d - 1, n + 5 * (10 ** d), t, f or 1, s)
        r += f755(d - 1, n + 7 * (10 ** d), t, f, s or 1)
    return r


ans = f755(len(N) - 1, 0, 0, 0, 0)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def cnt753(s):
  if int(s) > N:
    return 0
  if all(s.count(c) > 0 for c in ["7","5","3"]):
    ret = 1
  else:
    ret = 0
  for c in ["7","5","3"]:
    ret += cnt753(s+c)
  return ret
print(cnt753("0"))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**5)
N = int(input())

def rec(num, use):
    if num > N:
        return 0

    i = 0
    if (use == 0b111):
        i = 1

    return rec(num*10+7, use | 0b100)\
         + rec(num*10+5, use | 0b010)\
         + rec(num*10+3, use | 0b001)\
         + i

print(rec(0,0))

Submission status: Accepted

Solution code:
"""
dfsでとき直し114
7,5,3がそれぞれ1回以上現れる

3-3-3
   -5
   -7
 -5-3
   -5
   -7
 -7-3
   -5
   -7
とかそういうヤツ

3 33 35 37 5 
"""

import sys
sys.setrecursionlimit(100000)

cnt = 0
num = "0"
X = int(input())
def dfs(num,is3,is5,is7):
    # print(num,is3 and is5 and is7)
    global cnt
    if is3 and is5 and is7:
        cnt += 1 
    N = "357"
    for n in N:
        if int(num+n) > X: continue #終了条件
        if n == "3":
            dfs(num+n,True,is5,is7)
        elif n == "5":
            dfs(num+n,is3,True,is7)
        elif n == "7":
            dfs(num+n,is3,is5,True)


dfs("0",0,0,0)
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())


def dfs(x):
    ret = 0
    if int(x) > N:
        return ret
    if '7' in x and '5' in x and '3' in x:
        ret += 1
    for k in '753':
        ret += dfs(x + k)
    return ret


print(dfs('0'))

Submission status: Accepted

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

Submission status: Accepted

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

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


def solve(N: int):
    print(dfs('0',N))


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

def dfs(x, f3, f5, f7):
  cnt = 0
  if x>n:
    return 0
  if f3>0 and f5>0 and f7>0:
    cnt += 1

  t1 = x*10+3
  t2 = x*10+5
  t3 = x*10+7
  cnt += dfs(t1, f3+1, f5, f7)
  cnt += dfs(t2, f3, f5+1, f7)
  cnt += dfs(t3, f3, f5, f7+1)
  return cnt

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

Submission status: Accepted

Solution code:
N = input()

import itertools

num = int(N)
d = len(N)

lst = ['3', '5', '7']

arr = []
for j in range(3, d+1):
    arr += [int("".join(i)) for i in itertools.product(lst, repeat=j) if '3' in i and '5' in i and '7' in i]

cnt = sum([arr[k]<=num for k in range(len(arr))])
print(cnt)

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())
i=1
j=0
k=0
s=["3","5","7"]
d=["3","5","7"]
g=[]
k2=0
while i!=10:
    f=len(d)
    while j!=3:
        k = k2
        while k!=f:
            d.append(d[k]+s[j])
            k+=1


        j+=1
    k2 = f
    j=0
    i+=1
i=0
while i!=len(d):
    if ("3" in d[i])==True and ("5" in d[i])==True and ("7" in d[i])==True:
        i+=1
    else:
        del d[i]

d=list(map(int,d))
d.sort()
ans=0
i=0
x=d[i]
while x<=n:
    ans+=1
    i+=1
    x=d[i]

#print(d)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
import itertools
keta = len(str(n))
l = []
for i in range(3,keta + 1):
    l = l + list(itertools.product([7,5,3], repeat = i))
l = list(l)
l = map(lambda x: "".join(list(map(str, x))), l)
l = map(int, l)
l = list(l)
l = filter(lambda x: x <= n, l)
l = filter(lambda x: str(x).find("3") != -1, l)
l = filter(lambda x: str(x).find("5") != -1, l)
l = filter(lambda x: str(x).find("7") != -1, l)
l = list(l)
print(len(l))

Submission status: Accepted

Solution code:
N = int(input())
n = len(str(N))
s = ['3', '5', '7']
ans = 0
for d in range(3, n+1):
    for i in range(3 ** d):
        x = ''
        for j in range(d):
            x += s[(i//(3**j))%3]
        if '3' in x and '5' in x and '7' in x and int(x) <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = input()
l = len(n)
ls = [4**int(x) for x in range(l)]
ls.sort(reverse=True)

cnt = 0
for i in range(4**l):
    can = []
    for j in range(l):
        if i//ls[j]==3:
            can.append("7")
            i = int(i-ls[j]*3)
        elif i//ls[j]==2:
            can.append("5")
            i = int(i-ls[j]*2)
        elif i//ls[j]==1:
            can.append("3")
            i = int(i-ls[j])
        else:
            can.append("0")
    can = int("".join(can))
    can = list(str(can))
    if len(set(can)&{"0"})==0 and len({"3","5","7"}-set(can))==0:
        pass
    else:
        continue
    can = int("".join(can))
    if int(n)>=can:
        cnt+=1
    else:
        pass

print(cnt)

Submission status: Accepted

Solution code:
n = input()
key = ["3", "5", "7"]
cnt = 0
for k in range(3, len(n)+1):
    for i in range(3**k):
        t = []
        s = ""
        m = i
        for j in range(k):
            s += key[m%3]
            m = m//3
        if int(s) <= int(n) and len(set(list(s))) == 3:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
def sgs(k):
    return 3**k-3*(2**k-2)-3

n = int(input())
l = len(str(n))
if l <= 2:
    print(0)
    exit()
origin_list = ["3","5","7"]
lst=list(itertools.product(origin_list,repeat=l))
lst_753 = [i for i in lst if "3" in i and "5" in i and "7" in i]
lst_new = [int(''.join(i)) for i in lst_753]
sum_sgs = sum([sgs(i) for i in range(3,l)])

n_k = sum(i <= n for i in lst_new)

ans = sum_sgs+n_k
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
ans=0
def dfs(s):
	global ans
	if N<int(s):
		return 0
	if all([s.count(i) for i in "753"]):
		ans+=1
	for i in "753":
		dfs(s+i)
dfs("0")
print(ans)