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 as itt

N = input()

def check(snum):
    three = snum.count("3")
    five = snum.count("5")
    seven = snum.count("7")
    if (three == 0 or five == 0 or seven == 0) or (int(snum) > int(N)): return False
    else: return True

C = ["3", "5", "7"] #choice
digit = len(N)
cnt = 0
for d in range(3, digit+1): #3桁の入力から考える
    L = list(itt.product(C, repeat=d))
    for l in L:
        gen = "".join(l)
        if check(gen):
            #print(gen)
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

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

print(make753('0'))

Submission status: Accepted

Solution code:
n=int(input())
def solve(s):
    global n
    a=0
    for t in'357':
        u=''.join([s,t])
        if int(u)>n:
            return a
        a+=solve(u)+(sum(i in u for i in'357')>2)
    return a
print(solve(''))

Submission status: Accepted

Solution code:
import itertools
N = int(input())
cnt = 0
for i in range(1,11):
  for v in itertools.product('357', repeat = i):
    p = "".join(v)
    if('3' in v and '5' in v and '7' in v and int(p) <= N):
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
def nagosan():
    n=int(input())
    cnt=0
    for i in range(2,len(str(n))+1):
        a=list(itertools.product(['3','5','7'],repeat=i))
        for z in a:
            x=''.join(z)
            if int(x)>n:
                continue
            if '3' in x and '5' in x and '7' in x:
                cnt+=1
    return cnt
print(nagosan())

Submission status: Accepted

Solution code:
import numpy as np

S = int(input())
count = 0

dim = len(str(S))

box = np.zeros(([4]*dim),dtype='int64')

for j in range(dim):
    for i in range(4):
        I = [slice(None)]*box.ndim
        I[j] = i
        if i == 0:
            None
        else:
            box[tuple(I)]+= (i*2+1)*10**j

box = box.reshape(4**dim)

for i in np.sort(box).tolist():
    ss = [int(x) for x in list(str(i))]

    if i > S:
        break

    if list(set(ss)) == [3, 5, 7]:

        count = count + 1
print(count)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

stack = list('753')
ans = 0
while stack:
    x = stack.pop()
    
    if n < int(x):
        continue
        
    if all(x.count(c) > 0 for c in '753'):
        ans += 1
    stack.extend(x + c for c in '753')

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def count(lis, n):
    num = n
    keta = len(str(n))
    shurui = len(lis)
    ans = 0
    for i in range(1,keta):
        ans += shurui ** i
    while keta>=0:
        if keta == 0:
            ans += 1
            break
        keta -= 1
        kami = num // (10**keta)
        ok = sum(x<kami for x in lis)
        ans += ok * (shurui ** keta)
        if kami in lis:
            num = num % (10**keta)
        else:
            break
    return ans

N = int(input())

ans = count([7,5,3],N)-count([7,5],N)-count([5,3],N)-count([7,3],N)+count([7],N)+count([5],N)+count([3],N)
print(ans)

Submission status: Accepted

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

A = ['0', '3', '5', '7']
B = []
count=0
for i, j, k, l, m, n, o, p, q, r in itertools.product(A, A, A, A, A, A, A, A, A, A):
    ans= i + j + k + l + m + n + o + p + q + r
    ans = int(ans)
    if(ans <=a):
        ans = list(str(ans))
        if('0' not in ans and '3' in ans and '5' in ans and '7' in ans):
            count+=1
    else:
        break
print(count)

Submission status: Accepted

Solution code:
import itertools

def calc(nums, n, k):
    total = 0
    for i in range(k):
        total += nums[i] * n[i]
    return total

N = int(input())
k = len(str(N))

nums = [10 ** i for i in range(k)]
nums.reverse()

finish = False
count = 0
for i in range(3, k+1):
    if finish:
        break
    if i == k:
        flag = True
    else:
        flag = False
    for n in itertools.product([3,5,7], repeat=i):
        if 3 in n and 5 in n and 7 in n:
            if flag:
                if N < calc(nums, n, i):
                    finish = True
                    break
            count += 1
print(count)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
nums = [3, 5, 7]
res = 0
for i in range(10):
  for balls in itertools.product(nums, repeat=i):
    num = ''
    if 3 in balls and 5 in balls and 7 in balls:
      for j in range(i):
        num += str(balls[j])
      if int(num) > N:
        break
      res += 1

print(res)

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

def dfs(s):
    if int(s) > N:
        return 0
    #sが7,5,3をそれぞれ一つ以上含んでいる場合、+1、 else 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    #sに7,5,3のいずれかを付け足す
    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
    # 文字列sが七五三数だったら1(カウントするということ)
    for c in '753':
        ret += dfs(s+c)
    return ret
    
print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

def num(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 += num(s+c)
    return ret

print(num('0'))

Submission status: Accepted

Solution code:
UP = int(1e9)
s = set()


def dfs(n, f3, f5, f7):
    if n > UP:
        return
    if f3 and f5 and f7:
        s.add(n)
    dfs(n * 10 + 3, True, f5, f7)
    dfs(n * 10 + 5, f3, True, f7)
    dfs(n * 10 + 7, f3, f5, True)


dfs(0, False, False, False)
l = list(s)
l.sort()
n = int(input())
ans = 0
for i in l:
    if i <= n:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
UP = int(1e9)
s = set()
full = set('357')


def dfs(n):
    if n > UP:
        return
    if set(str(n)) == full:
        s.add(n)
    dfs(n * 10 + 3)
    dfs(n * 10 + 5)
    dfs(n * 10 + 7)


dfs(0)
l = list(s)
l.sort()
n = int(input())
ans = 0
for i in l:
    if i <= n:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())


ans = 0

def dfs(x, flags):
  if x <= N:
    global ans
    if flags == 7:
      ans += 1
  if x >= N:
    return
  dfs(x * 10 + 7, flags | 4)
  dfs(x * 10 + 5, flags | 2)
  dfs(x * 10 + 3, flags | 1)

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

Submission status: Accepted

Solution code:
n = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
#C - 755 解3
Set753 = {7, 5, 3}
List753 = [7, 5, 3]

N = int(input())

def getDigitList(n):
    list = []
    while n>0:
        list.append(n%10)
        n //= 10
    list.reverse()
    if list==[]: list = [0]
    return list

def gen(n):
    if n>N: return []
    else:
        d = getDigitList(n)
        #print(d) #
        if set(d)==Set753: 
            result = [n]
        else:
            result = []
        for a in List753:  result += gen(n*10+a)
        return result
                
result = gen(0)
#print(result) #
print(len(result))

Submission status: Accepted

Solution code:
import collections

n = int(input())
dq = collections.deque()
dq.append('3')
dq.append('5')
dq.append('7')
cnt = 0
while dq:
    v = dq.popleft()
    int_v = int(v)
    if int_v <= n:
        for c in '357':
            dq.append(v + c)
        if all([c in v for c in '357']):
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(n, is3, is5, is7):
    if(n > N): 
        return 0
    ans = 0
    if(is3 and is5 and is7): ans += 1
    ans += dfs(n * 10 + 3, True, is5, is7)
    ans += dfs(n * 10 + 5, is3, True, is7)
    ans += dfs(n * 10 + 7, is3, is5, True)
    return ans

if __name__ == "__main__":
    print(dfs(0, False, False, False))