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:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def dfs(s, N):
    if N < int(s):
        return 0

    ret = 1 if all([c in s for c in '753']) else 0
    for c in '753':
        ret += dfs(s + c, N)
    return ret


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


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
    result = solve(N)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
from copy import deepcopy
import math
import itertools

N = int(input())


## 入力整数Nの桁数を出力する
## 10**(out-1) <= in < 10**out
def int2digit(num):
  return(len(str(num)))

## k桁の753数を全て構成する
def mk753_digit(digit):
  lst_753_tuple = list(itertools.product([7,5,3], repeat=digit))
  lst_753_str = list(map(lambda x: ''.join(map(str, x)), lst_753_tuple))
  lst_753_contain7 = [s for s in lst_753_str if '7' in s]
  lst_753_contain75 = [s for s in lst_753_contain7 if '5' in s]
  lst_753_contain753 = [s for s in lst_753_contain75 if '3' in s]
  lst_753 = list(map(int, lst_753_contain753))
  return lst_753


ans = 0
digit = int2digit(N)
for k in range(digit):
  ans += len(mk753_digit(k))
lst_753_samedigit = mk753_digit(digit)
lst_753_samedigit_smaller = [x for x in lst_753_samedigit if x <= N]
ans += len(lst_753_samedigit_smaller)

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())

#753数かかくにんするための関数
#引数はstr
def check(num):
  if num.count("3") > 0 and num.count("5") > 0 and num.count("7") > 0:
    return True
  else:
    return False
  
ans = 0  
nums = deque()
nums.append(0)
for i in range(1,10): #一桁から9桁まで
  next_queue_list = deque()
  for j in nums:
    for k in [3,5,7]:
      new_num = j * 10 + k
      if new_num <= N:
        if check(str(new_num)):
          ans += 1
        next_queue_list.append(new_num)
  
  nums = next_queue_list
  
  
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())

S = str(N)
n = len(S)

ans = 0
for i in range(3, n + 1):
    for p in product(['3', '5', '7'], repeat=i):
        x = int(''.join(p))
        if x <= N and len(set(p) & {'3', '5', '7'}) == 3:
            ans += 1
print(ans)

Submission status: Accepted

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

def dfs(n, f1, f2, f3):
    if n > N:
        return
    if f1 and f2 and f3:
        global ans
        ans += 1

    dfs(n*10+7, True, f2, f3)
    dfs(n*10+5, f1, True, f3)
    dfs(n*10+3, f1, f2, True) 

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

Submission status: Accepted

Solution code:
import sys

input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
gcd = lambda a:functools.reduce(fractions.gcd,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:functools.reduce(lcm_base,a,1) # 最小公倍数(リスト)

init_dp = lambda v,n:[v]*(n)

import math
# 四捨五入はround
ceil = lambda a:math.ceil(a) # 切り上げ
floor = lambda a:math.floor(a) # 切り捨て

def dfs(s,N):
    ans = 0
    if s != '' and int(s) > N:return ans
    if all(c in s for c in '753'):ans+=1
    for c in '753':
        ans += dfs(s+c,N)
    return ans
    
def solution():
    N = input_int()
    sys.setrecursionlimit(N+10)
    ans = dfs('',N)
    print(ans)

if __name__ == '__main__':
    solution()

Submission status: Accepted

Solution code:
n=int(input())
length=len(str(n))
def f(x):
    return 3**x-3*(2**x)+3
answer=0
for i in range(1,length):
    answer=answer+f(i)
def g(i,s):
    if i==length:
        if int(s)<=n and '3' in s and '5' in s and '7' in s:
            return 1
        else:
            return 0
    else:
        return g(i+1,s+'3')+g(i+1,s+'5')+g(i+1,s+'7')
answer=answer+g(0,'')
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
s=['0','3','5','7']
must = ['3','5','7']
count = 0
for i_9 in range (4):
    for i_8 in range (4):
        for i_7 in range (4):
            for i_6 in range (4):
                for i_5 in range (4):
                    for i_4 in range (4):
                        for i_3 in range (4):
                            for i_2 in range (4):
                                for i_1 in range (4):
                                    num =s[i_9]+s[i_8]+s[i_7]+s[i_6]+s[i_5]+s[i_4]+s[i_3]+s[i_2]+s[i_1]
                                    num = int(''.join(list(map(str,num))))
                                    if (num<=N) & ('0' not in list(str(num))) & ('3' in list(str(num))) & ('5' in list(str(num))) & ('7' in list(str(num))) :
                                        count +=1
                                        
print(count)

Submission status: Accepted

Solution code:
S = int(input())

def dfs(N, a, b, c):
  if int(N) > S:
    return 0
  res = 0 if a == 0 or b == 0 or c == 0 else 1
  for i in "357":
    if i == "3":
      res += dfs(N+i, a+1, b, c)
    if i == "5":
      res += dfs(N+i, a, b+1, c)
    if i == "7":
      res += dfs(N+i, a, b, c+1)
  return res

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input())

num_list = [3, 5, 7]
count = 0
while len(num_list) > 0:
    base = num_list.pop()
    for i in [3, 5, 7]:
        v = base*10+i
        if v <= N:
            num_list.append(v)
            if ('3' in str(v)) and ('5' in str(v)) and ('7' in str(v)):
                count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())


# N以下の753数を全列挙
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())
ans = []

def shichigo(n):
    global ans
    if int(n) > N:
        return
    if all([(s in n) for s in "753"]):
        ans.append(n)
    shichigo(str(int(n) * 10 + 3))
    shichigo(str(int(n) * 10 + 5))
    shichigo(str(int(n) * 10 + 7))

if N < 357:
    print(0)
else:
    shichigo('3')
    shichigo('5')
    shichigo('7')
    print(len(set(ans)))

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
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().strip())
count = 0
for i in range(3, len(str(N))+1):
  for n in itertools.product('753', repeat=i):
    num = int(''.join(n))
    if num > N:
      continue
    if len(set(n)) == 3:
      count += 1
print(count)

Submission status: Accepted

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

print(dfs('0'))

Submission status: Accepted

Solution code:
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    return True

n = input()

l = [[] for i in range(len(n))]
l[0] = ['3','5','7']
for i in range(1,len(l)):
    for j in range(len(l[i-1])):
        l[i].append('3'+l[i-1][j])
        l[i].append('5'+l[i-1][j])
        l[i].append('7'+l[i-1][j])

ans = 0
for i in range(len(l)):
    for j in range(len(l[i])):
        if int(n) >= int(l[i][j]):
            if shichigo(l[i][j]):
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    x = s.replace('3','').replace('5','').replace('7','')
    if x=='':
        return True
    return False

n = input()

l = [[] for i in range(len(n))]
l[0] = ['3','5','7']
for i in range(1,len(l)):
    for j in range(len(l[i-1])):
        l[i].append('3'+l[i-1][j])
        l[i].append('5'+l[i-1][j])
        l[i].append('7'+l[i-1][j])

ans = 0
for i in range(len(l)):
    for j in range(len(l[i])):
        if int(n) >= int(l[i][j]):
            if shichigo(l[i][j]):
                ans += 1

print(ans)

Submission status: Accepted

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

def dfs(n):
    if n > N:
        return 0
    ret = 0
    count = 0
    for i in ['3', '5', '7']:
        if i in str(n):
            count += 1
    if count == 3:
        ret += 1
    n *= 10
    for i in [3, 5, 7]:
        ret += dfs(n+i)
    return ret

print(dfs(0))

Submission status: Accepted

Solution code:
from math import log10
from itertools import product

N = int(input())
keta = int(log10(N)) + 1

if keta < 3:
    print(0)
    exit()

count = 0
# keta 桁の 753 数と N を比較
for k in range(3, keta+1):
    for pair in product([3, 5, 7], repeat=k):
        if len(set(pair)) < 3:
            continue
        tmp = 0
        for i, p in enumerate(pair):
            tmp += p * (10**(k-i-1))
        if N >= tmp:
            count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0
    f = []
    for n in '753':
        if n in s:
            f.append(True)
        else:
            f.append(False)
    ans = 1 if all(f) else 0
    for n in '753':
        ans += dfs(s + n)
    return ans


print(dfs('0'))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
num = ['3', '5', '7']
numbers_753 = []
prev = ['']
for _ in range(9):
    temp = []
    generated = []
    for p in prev:
        for n in num:
            cand = p+n
            generated.append(cand)
            if '3' in cand and '5' in cand and '7' in cand:
                temp.append(int(p+n))
    numbers_753 += temp
    prev = generated
numbers_753 = np.array(numbers_753)
print(sum(numbers_753 <= N))

Submission status: Accepted

Solution code:
from itertools import permutations

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:
s = input()
d = len(s)
n = int(s)
cand = []
def produce(text):
  if len(text) == d + 1:
    if '3' in text and '5' in text and '7' in text:
      cand.append(int(text))
    return
  if text[-1] == '0':
    for item in ['0', '3', '5', '7']:
      produce(text + item)
  else:
    for item in ['3', '5', '7']:
      produce(text + item)
produce('0')
print(sum(n >= item for item in cand))

Submission status: Accepted

Solution code:
ans = 0

def rec(num,flag,co,N):
    global ans
    if num>N:
         return  0

    else:
        if flag  == 0b111:
            # print(ans)
            ans += 1
        return rec(num * 10 + 7, flag|0b001,co + 1,N ) + rec(num * 10 + 3,flag|0b100,co + 1,N ) +rec(num * 10 + 5,flag|0b010 ,co + 1,N )
def c():
    bit07 = 0b001
    bit05 = 0b010
    bit03 = 0b100
    global ans
    N = input()
    N = int(N)
    rec(3,bit03,0,N)
    rec(5,bit05,0,N)
    rec(7,bit07,0,N)

    print(ans)
if __name__ == "__main__":
    c()

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
num = ['','3','5','7']
A = set() 
for i in product(num,repeat=9):
    x = "".join(i)
    if len(set(x)) == 3:
        if (int(x) not in A) and (int(x) <= n):
            A.add(int(x))
print(len(A))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
digit = int(np.log10(N))+1

def ok(s):
  if '7' in s and '5' in s and '3' in s and int(s) <= N:
    return True
  return False

def dfs(cur, s):
  if cur == digit:
    return ok(s)
  else:
    ret = ok(s)
    for i in '357':
      ret += dfs(cur+1, s+i)
  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
    b=(all(map(s.count,"357")))
    for c in "357":
        b+=dfs(s+c)
    return b
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 = input()
N_list = []

def func(M_len, M):
  if M_len == 0:
    if len(set(list(M))) == 3:
      N_list.append(M)
  else:
    for i in ['3','5','7']:
      func(M_len-1, M + i)
      
for i in range(len(N)+1):
  func(i, '')
print(len([x for x in N_list if int(x) <= int(N)]))

Submission status: Accepted

Solution code:
N = int(input())
A = []

def f(s):
    if int(s) > N:
        return 0
    if all(s.count(i) >= 1 for i in '753'):
        A.append(int(s))
    for i in '753':
        f(s + i)

f('0')
print(len(A))
# print(sorted(A))

Submission status: Accepted

Solution code:
N = int(input())
A = []

def f(s):
    if s != '' and eval(s) > N:
        return 0
    if all(s.count(i) >= 1 for i in '753'):
        A.append(eval(s))
    for i in '753':
        f(s + i)

f('')
print(len(A))
# print(sorted(A))

Submission status: Accepted

Solution code:
import itertools

N = int(input())

c = 0
n = str(N)
L = len(n)

if L >= 3:
  for j in range(L-2):
    for i in itertools.product(['3', '5', '7'], repeat=j+3):
      if int("".join(i)) <= N and len(set(i)) == 3:
        c += 1

print(c)

Submission status: Accepted

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

nums = set([int("".join(n)) for r in range(1,9+1)
              for n in itertools.product(list("753"), repeat=r)])

for chars in ["75","53","37","7","5","3"]:
    nums -= set([int("".join(n)) for r in range(1,9+1)
                   for n in itertools.product(list(chars), repeat=r)])


print(len([n for n in list(nums) if n <= N]))

Submission status: Accepted

Solution code:
def f(i,ans):
    if int(i) > N:
        return ans
    i = str(i)
    ans += 1 if all([i[1:].count(a) for a in A]) else 0
    for a in A:
        ans += f(i+a,ans)-ans
    return ans
  
N = int(input())
ans = 0
A = '357'
print(f(0,0))

Submission status: Accepted

Solution code:
import math,sys,itertools

N = int(input())

cnt = 0

base = [3,5,7]
#num = [357,375,537,573,735,753]
num = set(base)
ans = {}
keta = math.log10(N + 1)
keta = math.ceil(keta) 
tmplist = [0]
for i in range(keta):
    newlist = []
    for j in tmplist:
        for k in base:
            newlist += [j + k * 10 ** i]
        
    num |= set(newlist)
    tmplist = newlist

for x in list(num):
    s = str(x)
    flag = [False,False,False]
    for i in s:
        if i == '3':flag[0] = True
        if i == '5':flag[1] = True
        if i == '7':flag[2] = True
        if flag[0] and flag[1] and flag[2] :
            if x <= N:cnt += 1            
            break
    

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())

# 文字列(3,5,7)を後ろに付け加えていく

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

print(dfs('0'))

Submission status: Accepted

Solution code:
def dfs(x, bit) :
  if x > N :
    return 0
  res = bit == 7
  res += dfs(10*x + 3, bit|1)
  res += dfs(10*x + 5, bit|2)
  res += dfs(10*x + 7, bit|4)
  return res

N = int(input())
print(dfs(0, 0))

Submission status: Accepted

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

N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    if all([s.count(i) for i in "753"]):
        result = 1
    else:
        result = 0
    
    for i in "753":
        result += dfs(s+i)
    return result

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 math

n = int(input())
first_pos = int(math.log10(n))
count = 0


def find(pos, found=[], permit_9=False, permit_zero=False):
    global n
    global count

    if pos < 0:
        return

    digit = 9 if permit_9 else (n // (10**pos)) % 10

    #print('%d %d %d %d %s %s' % (pos, n, digit, 10**pos, found, permit_9))

    for i in range(0, digit + 1):
        if i == 0 and permit_zero:
            find(pos - 1, found=found, permit_9=permit_9 or i < digit, permit_zero=True)
        if i == 3 or i == 5 or i == 7:
            found.append(i)
            find(pos - 1, found=found, permit_9=permit_9 or i < digit, permit_zero=False)
            if pos == 0 and set(found) == {3, 5, 7}:
                #print('== OK == %s' % found)
                count += 1
            found.pop()

#print(first_pos)
find(first_pos, found=[], permit_9=False, permit_zero=True)
print(count)

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:
from itertools import product
N = int(input())

cnt = 0
for i in range(3,10):
    for v in product('357',repeat=i):
        val = ''.join(v)
        if int(val) <= N and '3' in val and '5' in val and '7' in val:
           cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = input()

def dfs(now):
    if int(now) > int(n):
        return 0

    counter = 1 if ("7" in now and "5" in now and "3" in now) else 0
    for i in "357":
        counter += dfs(now + i)

    return counter

print(dfs("0"))

Submission status: Accepted

Solution code:

ans = 0

def check(num_str):
    for i in ['7', '5', '3']:
        if i not in num_str:
            return 0
    return 1

def make_data(num, num_str):
    global ans
    if num < int(num_str):
        return
    if check(num_str):
        ans += 1

    make_data(num, num_str + '7')
    make_data(num, num_str + '5')
    make_data(num, num_str + '3')


def main():
    num = int(input())
    make_data(num, '0')

    global ans
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
l=len(str(n))
if l<3:
  print(0)
else:
  ans=set()
  b=[0,3,5,7]
  for i in range(4**l-1):
    a=0
    c=1
    while i>0:
      a+=c*b[i%4]
      i//=4
      c*=10
    if "3" in str(a) and "5" in str(a) and "7" in str(a):
      if n>=a:
        if "0"not in str(a):
          ans.add(a)
  print(len(ans))

Submission status: Accepted

Solution code:
from collections import deque


def bfs(parent, n):
    queue = deque()
    queue.append(parent)
    d = ['3', '5', '7']
    ans = 0

    while queue:
        s = queue.popleft()
        for di in d:
            t = s+di
            if n < int(t):
                return ans
            elif int(t) <= n and '3' in t \
                    and '5' in t and '7' in t:
                ans += 1

            queue.append(t)


if __name__ == "__main__":
    n = int(input())

    print(bfs('3', n)+bfs('5', n)+bfs('7', n))

Submission status: Accepted

Solution code:
import itertools

n = int(input())
num = ['3','5','7']
elements = []
for i in range(1,len(str(n))+1):
    options = itertools.product(num, repeat=i)
    for s in options:
        num1 = ''.join(s)
        elements.append(num1)

cnt = 0

for i in range(len(elements)):
    if int(elements[i]) <= n:
        if '3' in elements[i] and '5' in elements[i] and '7' in elements[i]:
            cnt += 1
    else:
        break

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import itertools
n = int(input())
nums = []
pre_nums = ['3','5','7']

for i in range(3,10):
    for ids in itertools.product(pre_nums, repeat=i):
        if '3' in ids and '5' in ids and '7' in ids:
            nums.append(int(''.join(ids)))
for i,num in enumerate(nums):
    if n < num:
        print(i)
        break
else:
    print(len(nums))

Submission status: Accepted

Solution code:
N = int(input())
def check(x):
    x = str(x)
    return x.count("3") >= 1 and x.count("5") >= 1 and x.count("7") >= 1
def dfs(x):
    if x > N or x >= 10**9:
        return 0
    ans = 0
    ans += int(check(x))

    ans += dfs(10 * x + 3)
    ans += dfs(10 * x + 5)
    ans += dfs(10 * x + 7)
    return ans
print(dfs(0))

Submission status: Accepted

Solution code:
n = int(input())


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


print(dfs(''))

Submission status: Accepted

Solution code:
import itertools

n = int(input())

ans = 0
for r in range(1, 10):
    for s in itertools.product('357', repeat=r):
        d = int(''.join(s))
        if '3' in s and '5' in s and '7' in s and d <= n:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(raw_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:
#!/usr/bin/env python3
import sys
from pprint import pprint


# Digit DP
def solve(N: int):
    s = str(N + 1)
    n = len(s)
    # dp[idx][smaller][started][3][5][7]
    dp = [[[[[[0 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(n + 1)]
    dp[0][0][0][0][0][0] = 1
    for i in range(0, n):
        for smaller in range(2):
            for started in range(2):
                for i1 in range(2):
                    for i2 in range(2):
                        for i3 in range(2):
                            for nex in [0, 3, 5, 7]:
                                if not smaller and nex > int(s[i]):
                                    #print(i, nex)
                                    continue
                                if started and nex == 0:
                                    continue
                                #print(i, smaller, started, i1, i2, i3)
                                #print(dp[0][0][0][0][0][0])
                                #if not (smaller | nex < int(s[i])):
                                #    print(' --- ')
                                #    print(i, smaller, started, i1, i2, i3, nex, int(s[i]), nex < int(s[i]))
                                #    print(smaller, nex < int(s[i]))
                                #    print(smaller or nex < int(s[i]))
                                #    print(' --- ')

                                #dp[i + 1][smaller | nex < int(s[i])][started | nex > 0][i1 | nex == 3][i2 | nex == 5][i3 | nex == 7] += \
                                dp[i + 1][smaller or nex < int(s[i])][started or nex > 0][i1 or nex == 3][i2 or nex == 5][i3 or nex == 7] += \
                                    dp[i][smaller][started][i1][i2][i3]
        #pprint(dp[i])
        #print()
    ret = dp[n][1][1][1][1][1]
    #pprint(dp[n])
    print(ret)
    return


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 is753(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+=is753(s+c)
    return ret
print(is753('0'))

Submission status: Accepted

Solution code:
#coding: utf-8
from collections import Counter
N = int(input())
l = ["0", "3", "5", "7"]
ans = ["0"] * 9
cnt = 0
for a in l:
    ans[0] = a
    for b in l:
        ans[1] = b
        for c in l:
            ans[2] = c
            for d in l:
                ans[3] = d
                for e in l:
                    ans[4] = e
                    for f in l:
                        ans[5] = f
                        for g in l:
                            ans[6] = g
                            for h in l:
                                ans[7] = h
                                for i in l:
                                    ans[8] = i
                                    ans_i = int("".join(ans))
                                    ans_c = Counter(str(ans_i))
                                    if ans_i <= N and "0" not in str(ans_i) and len(ans_c.keys()) == 3 and len(str(ans_i)) >= 3:
                                        cnt += 1
print(cnt)

Submission status: Accepted

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

def dfs(N: int, digit: int,cur: str):
    if len(cur) < digit:
        return dfs(N,digit,cur+"3") + dfs(N,digit,cur+"7") + dfs(N,digit,cur+"5")
    else:
        if int(cur) > N:
            return 0
        if cur.count("3") > 0 and cur.count("7") > 0 and cur.count("5"):
            return 1
        else:
            return 0


def solve(N: int):
    digit = math.ceil(math.log10(N))
    sum = 0
    for i in range(3,digit+1):
        sum += dfs(N,i,"")
    print(sum)
    return


# Generated by 1.1.4 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())

cnt = 0
def dfs(s):
    global cnt
    if '3' in s and '5' in s and '7' in s and int(s) <= N:
        cnt += 1
    if len(s) >= 10:
        return cnt
    dfs(s + '3')
    dfs(s + '5')
    dfs(s + '7')
    return cnt

print(dfs(''))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import functools
import itertools
INF = float("inf")


@functools.lru_cache(maxsize=None)
def pow(b, n):
    return b**n


def f(n):
    # n桁の753数
    if n < 3:
        return 0

    return pow(3, n) - 3*pow(2, n) + 3


def solve(N: int):
    ketamax = len(str(N))

    ans = 0
    # 桁
    for i in range(3, ketamax):
        ans += f(i)
    # print(ans)
    # 最大桁数の場合だけごにょる(O(N))
    for item in itertools.product(["3", "5", "7"], repeat=ketamax):
        if "3" not in item or "5" not in item or "7" not in item:
            continue
        elif int("".join(item)) > N:
            continue
        else:
            ans += 1
    print(ans)
    return


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 count(i,x,y,z):
	if i > N:
		return 0
	c = 1 if x * y * z > 0 else 0
	c += count(i*10+7, x+1, y, z)
	c += count(i*10+5, x, y+1, z)
	c += count(i*10+3, x, y, z+1)
	return c

print(count(0,0,0,0))

Submission status: Accepted

Solution code:
n = int(input())
def counter(num1, num2):
	if num2 == "0":
		num21 = "3"
		num22 = "5"
		num23 = "7"
		return counter(num1, num21) + counter(num1, num22) + counter(num1, num23)
	elif int(num2) > num1:
		return 0
	else:
		result = 0
		num21 = "3" + num2
		num22 = "5" + num2
		num23 = "7" + num2
		if "3" in num21 and "5" in num21 and "7" in num21 and int(num21) <= num1:
			result += 1
		if "3" in num22 and "5" in num22 and "7" in num22 and int(num22) <= num1:
			result += 1
		if "3" in num23 and "5" in num23 and "7" in num23 and int(num23) <= num1:
			result += 1
		return counter(num1, num21) + counter(num1, num22) + counter(num1, num23) + result

print(counter(n, "0"))

Submission status: Accepted

Solution code:
N=int(input())

def dfs(s):
    if len(s)==len(str(N)):
        return 0
    ans=0
    for c in "357":
        if int(s+c)<=N and all(a in s+c for a in "357"):
            ans+=1
        ans+=dfs(s+c)
    return ans
print(dfs(''))

Submission status: Accepted

Solution code:
n=int(input())
import bisect
import itertools
l=len(str(n))
ans=[]
num=[]
x=['3', '5', '7']
for k in range(3,l+1):
    m=list(itertools.product(x, repeat=k))
    num.extend(m)
for i in range(len(num)):
    y=num[i]
    if '3' in y and '5' in y and '7' in y:
        number=''
        for j in range(len(y)):
            number+=y[j]
        ans.append(int(number))
ans.sort()
print(bisect.bisect_right(ans, n))

Submission status: Accepted

Solution code:
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0
    ct = 1 if all(s.count(a) for a in '357') else 0
    ct += dfs(s+'3')
    ct += dfs(s+'5')
    ct += dfs(s+'7')
    return ct


print(dfs('0'))

Submission status: Accepted

Solution code:
def makestr(lst):
	s = ''
	for i in range(0, len(lst)):
		s = s + lst[i]
	return s

N = int(raw_input())
queue = [[]]
cnt = 0
while(True):
	now = queue.pop(0)
	if now != []:
		if int(makestr(now)) > N: break
		elif '3' in now and '5' in now and '7' in now:
			cnt += 1
	lst = ['3', '5', '7']
	for i in range(0, 3):
		next = []
		for j in range(0, len(now)):
			next.append(now[j])
		next.append(lst[i])
		queue.append(next)

print cnt

Submission status: Accepted

Solution code:
N = int(input())

le = len(str(N))
al = ['3','5','7']
al2 = []
for i in range(le-1):
    al1 = []
    for n in al:
        a = int(str(n)+'3')
        b = int(str(n)+'5')
        c = int(str(n)+'7')
        al1.append(a)
        al1.append(b)
        al1.append(c)
        al2.append(a)
        al2.append(b)
        al2.append(c)
    al = al1

cnt = 0
for n in al2:
    if n <= N:
        if all(str(n).count(c) > 0 for c in '753'):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools
ans = 0
nums = []
N = int(input())
for k in range(1, 10):
    s = itertools.product(['3', '5', '7'], repeat = k)
    for seq in s:
        num = ''.join(seq)
        nums.append(num)
for num in nums:
    if '3' in num and '5' in num and '7' in num and int(num) <= N:
        ans += 1
print(ans)