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: Runtime Error

Solution code:
num753 = []
num753.append([0,0,0,0,0,0,0])  #3,5,7,35,37,57,357
num753.append([1,1,1,0,0,0,0])

for i in range(1,10):
    num753.append([num753[i][0],num753[i][1],num753[i][2],num753[i][0]+num753[i][1]+num753[i][3]*2,num753[i][0]+num753[i][2]+nu
m753[i][4]*2,num753[i][1]+num753[i][2
]+num753[i][5]*2,num753[i][3]+num753[i][4]+num753[i][5]+num753[i][6]*3])

N = input()
ans = 0
for i in range(len(N)):
    ans += num753[i][6]

check3 = False
check5 = False
check7 = False
for i in range(len(N)):
    if int(N[i])<3:
        break
    if check5:
        ans += num753[len(N)-i-1][2]+num753[len(N)-i-1][4]
    if check7:
        ans += num753[len(N)-i-1][1]+num753[len(N)-i-1][3]
    if check5 and check7:
        ans += num753[len(N)-i-1][0]
    if int(N[i])==3:
        check3 = True
        continue
    ans += num753[len(N)-i-1][5]+num753[len(N)-i-1][6]
    if int(N[i])<5:
        break
    if check3:
        ans += num753[len(N)-i-1][2]+num753[len(N)-i-1][5]
    if check7:
        ans += num753[len(N)-i-1][0]+num753[len(N)-i-1][3]
    if check3 and check7:
        ans += num753[len(N)-i-1][1]
    if int(N[i])==5:
        check5 = True
        continue
    ans += num753[len(N)-i-1][4]+num753[len(N)-i-1][6]
    if int(N[i])<7:
        break
    if check3:
        ans += num753[len(N)-i-1][1]+num753[len(N)-i-1][5]
    if check5:
        ans += num753[len(N)-i-1][0]+num753[len(N)-i-1][4]
    if check3 and check5:
        ans += num753[len(N)-i-1][2]
    if int(N[i])==7:
        check7 = True
        continue
    ans += num753[len(N)-i-1][3]+num753[len(N)-i-1][6]
    break

print(ans)

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

Solution code:
import itertools as t;N=input();X=[];for i in range(9):X+=list(t.product('357',repeat=i));print(sum(len(set(i))>2and int(''.join(i))<=int(N)for i in X))

Submission status: Runtime Error

Solution code:
n = int(raw_input())
nd = len(str(n))

a3 = [357, 375, 537, 573, 735, 753]
arr_a = [[]for i in range(nd-2)]
arr_a[0] = a3
all_num = [357, 375, 537, 573, 735, 753]
for i in range(1, nd-2):
    for j in arr_a[i-1]:
        arr_a[i].append(j*10+3)
        arr_a[i].append(j*10+5)
        arr_a[i].append(j*10+7)
    for k in arr_a[i]:
        all_num.append(k)
# print arr_a

def only_2kind(a,b,n):
    if n <= 3:
        return []
    else:
        all_num = []
        o = [10 * a + b, 10 * b + a, 10 * a + a, 10 * b + b]
        for j in range(n-3):
            o2 = []
            for i in range(len(o)):
                o2.append(o[i]*10+a)
                o2.append(o[i] * 10 + b)
            # print o2
            for i in range(len(o2)):
                if o2[i] != int(str(a)*(j+3)) and o2[i] != int(str(b) * (j + 3)):
                    all_num.append(o2[i]*10+(15-a-b))
            o = o2
        return all_num

all_num+=(only_2kind(3,5,nd)+only_2kind(5,7,nd)+only_2kind(3,7,nd))
all_num.append(n)
all_num.sort()
# print len(all_num)
# for i in all_num:
#     print i
print all_num.index(n)

Submission status: Runtime Error

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

for i in range(N+1):
    if(all(i.count(c) for c in '753')):
        ret += 1

print(ret)

Submission status: Runtime Error

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 # s 自体が七五三数なら +1 
  for c in '753':
    ret += dfs(s + c)
  return ret
print(dfs('0'))

Submission status: Runtime Error

Solution code:
def add(a):
	if int(a)>n:
		return 0
	else:
		ans = 0
		a = '' if int(a)==0 else a
		if a.find('3')>-1 and a.find('5')>-1 and a.find('7')>-1:
			ans+=1
		for i in [3,5,7]:
			ans+=add(a+str(i))
		return ans

n = int(input())
print(add(''))

Submission status: Runtime Error

Solution code:
import numpy as np

def list753(n):
    if n == 1:
        return np.array([3,5,7],dtype=np.int)
    else:
        prev = list753(n-1)
        return np.concatenate((10*prev+3,10*prev+5,10*prev+7))

def all_list753(n):
    return np.concatenate(tuple([list753(i) for i in range(3,n+1)]))

Nstr = input()
N = int(Nstr)
Nlen = len(Nstr)

candidates = all_list753(Nlen)
ans = 0

for c in candidates:
    if c > N:
        continue
    cstr = str(c)
    if '3' in cstr and '5' in cstr and '7' in cstr:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

def dfs(s):
  if int(s) > N: #sがNより大きくなったら再帰終了
    return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0　#sが七五三数ならretに1を入れる
  for c in '753':
    ret += dfs(s+c)
  return ret

print(dfs('0'))　#s='0'からスタート

Submission status: Runtime Error

Solution code:
n = input()
ans = 0
def jud(i):
    i = str(i)
    thr = 0
    fiv = 0
    sev = 0
    for j in range(len(i)):
        if i[j] == '3':
            thr += 1
        elif i[j] == '5':
            fiv += 1
        elif i[j] == '7':
            sev += 1
        else:
            return 'errrrrror'
    if thr >= 1 and fiv >= 1 and sev >= 1:
        return 1
    else:
        return 0

def jud2(i):
    i = str(i)
    thr = 0
    fiv = 0
    sev = 0
    for j in range(len(i)):
        if i[j] == '0':
            thr += 1
        elif i[j] == '1':
            fiv += 1
        elif i[j] == '2':
            sev += 1
        else:
            return 'errrrrror'
    if thr >= 1 and fiv >= 1 and sev >= 1:
        return 1
    else:
        return 0

for i in range(int(n), 0, -1):
    if jud(i) == 1:
        num = ''
        i = str(i)
        for j in range(len(i)):
            if i[j] == '3':
                num += '0'
            elif i[j] == '5':
                num += '1'
            else:
                num += '2'
        break

def nsin(X,n):
    if(int(X/n)):
        return nsin(int(X/n), n) + str(X%n)
    return str(X%n)

def base10(i):
    i = str(i)
    ret = 0
    for j in range(len(i)):
        ret += int(i[j]) * pow(3, (len(i) - j - 1))
    return ret + 1

ans = 0
if base10(num) >= 4:
    for j in range(len(num), 2, -1):
        for i in range(base10(num) + 1, 4, -1):
            if jud2(nsin(i, 3).zfill(j)) == 1:
                ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import math
def numberof753bydig(dig,nummustcontain=3):
    if nummustcontain==3:
        ex=3*2**dig-3
    elif nummustcontain==2:
        ex=2*2**dig-1
    elif nummustcontain==1:
        ex=2**dig
    else:
        ex=0
    return 3**dig-ex
def numberof753(n,used=set()):
    if n==0: return 0
    dig=math.ceil(math.log10(n))
    res=0
    if len(used)==0:
        res=sum(numberof753bydig(i) for i in range(1,dig))
    top=n//10**(dig-1)
    if top in (3,5,7):
        res+=numberof753(n%10**(dig-1),used.union({top}))
    if top>3:
        res+=numberof753bydig(dig-1,3-len(used.union({3})))
    if top>5:
        res+=numberof753bydig(dig-1,3-len(used.union({5})))
    if top>7:
        res+=numberof753bydig(dig-1,3-len(used.union({7})))
    if len(used)==3 or {n}=={3,5,7}.difference(used):
        res+=1
    return res
print(number753(int(input())))

Submission status: Runtime Error

Solution code:
import math
def numberof753(n,used=set()):
    if n==0: return 1 if used=={7,5,3} else 0
    dig=math.ceil(math.log10(n))
    res=0
    if len(used)==0:
        res=sum(numberof753bydig(i) for i in range(1,dig))
    top=n//10**(dig-1)
    if top in (3,5,7):
        res+=numberof753(n%10**(dig-1),used.union({top}))
    if top>3:
        res+=numberof753bydig(dig-1,3-len(used.union({3})))
    if top>5:
        res+=numberof753bydig(dig-1,3-len(used.union({5})))
    if top>7:
        res+=numberof753bydig(dig-1,3-len(used.union({7})))
    return res
print(numberof753(int(input())))

Submission status: Runtime Error

Solution code:
n = int(input())
a = len(str(n))
lst = [[3,5,7]]
tfs = [3,5,7]
for i in range(1,a):
    l = []
    for v in lst[i-1]:
        for t in tfs:
            l.append(int(str(v) + str(t)))
    lst.append(l)
s = 0
for l in lst:
    for v in l:
        if is753(v) and v <= n:
            s+=1
print(s)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import itertools
x = int(input())
l = [3, 5, 7]

h = itertools.combinations_with_replacement(l, 4)

cnt = 0
for v in itertools.combinations_with_replacement(l, 4):
    if (3 in v and 5 in v and 7 in v):
        if v < x:
            cnt += 1

h_list = list(itertools.combinations_with_replacement(l, 4))

print (cnt)

Submission status: Runtime Error

Solution code:
N = input()
N_ = len(N)
A = N_ * N_ - 1 * N_ - 2

if int(N) < 357:
  print(0)
elif int(N[0]) < 2:
  A = N_ - 1 * N_ - 2 * N_ - 3
elif int(N[0]) == 3 or int(N[0]) == 4:
  A = N_ - 1 * N_ - 2
elif int(N[0]) == 5 int(N[0]) == 6:
  A = 2 * N_ -1 * N_ -2
elif int(N[0]) >= 7:
  A = N_ * N_ - 1 * N_ - 2
  

print(A)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <bitset>
#include <tuple>
#include <stack>
#include <utility>

using namespace std;

int func753(int i){
    int c3 = 0, c5 = 0, c7 = 0;
    while(i > 0){
        if(i%10 == 3){
            c3 += 1;
            i = i/10;
        }
        else if(i%10 == 5){
            c5 += 1;
            i = i/10;
        }
        else if(i%10 == 7){
            c7 += 1;
            i = i/10;
        }
        else return 0;
    }
    if(c3*c5*c7 != 0) return 1;
    return 0;
}

int main(){
    int N;
    cin >> N;
    int n = N, keta = 0;
    while(n > 0){
        keta += 1;
        n = n/10;
    }
    int ans = 0, i=357;
    while(i <= N){
        if(func753(i)) ans += 1;
        if(i%10 == 3){
            i += 2;
        }
        else if(i%10 == 5){
            i+= 2;
        }
        else{
            if(i%100 == 37) i += 10;
            if(i%100 == 57) i += 10;
            if(i%100 == 77) i += 50;
            i += 6;
        }
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
N753_list = [0] * len_N

N3 = 0
N5 = 0
N7 = 0

N35_list = [0] * len_N
N57_list = [0] * len_N
N73_list = [0] * len_N


ans_c = 0
        
if (N_list[0] == 7)or(N_list[0] == 8)or(N_list[0] == 9):
    for n in range(3,data_size+1):
        ans_c = ans_c + 3**n - (2**n)*3 + 3
    print(ans_c)
elif (N_list[0] == 5)or(N_list[0] == 6):
    for n in range(3,data_size+1):
        ans_c = 3*(ans_c + 3**(n-1) - (2**(n-1))*3 + 3)
    print(ans_c)
elif (N_list[0] == 3)or(N_list[0] == 4):
    for n in range(3,data_size+1):
        ans_c = ans_c + 3**(n-1) - (2**(n-1))*2 + 3
    for n in range(3,data_size+1):
        ans_c = ans_c + 3**(n-1) - (2**(n-1))*3 + 3
    print(ans_c)
elif (N_list[0] == 1)or(N_list[0] == 2):
    for n in range(3,data_size+1):
        ans_c = ans_c + 3**(n-1) - (2**(n-1))*3 + 3
    print(ans_c)

Submission status: Runtime Error

Solution code:
n=int(input())
ans=0
if n<10**8:
  if n%2==0:
    for i in range(1,n-1,2):
      sum3=0
      sum5=0
      sum7=0
      x=str(i)
      l=len(x)
      for j in range(l):
        if x[j]=='3':
          sum3 += 1
        elif x[j]=='5':
          sum5 += 1
        elif x[j]=='7':
          sum7 += 1
        if (sum3 + sum5 + sum7 == l) and (sum3>0) and(sum5>0) and (sum7>0):
          ans+=1
  else:
    for i in range(1,n,2):
      sum3=0
      sum5=0
      sum7=0
      x=str(i)
      l=len(x)
      for j in range(l):
        if x[j]=='3':
          sum3 += 1
        elif x[j]=='5':
          sum5 += 1
        elif x[j]=='7':
          sum7 += 1
        if (sum3+sum5+sum7==l) and (sum3>0) and(sum5>0) and (sum7>0):
          ans+=1
print(ans)
else:
print(0)

Submission status: Runtime Error

Solution code:
def C3():
    tmp = []
    import  copy

    for i in range(9):
        tmp.append([])
        tmp[i].append(3 * pow(10, i))
        tmp[i].append(5 * pow(10, i))
        tmp[i].append(7 * pow(10, i))

    tmp2 = [copy.copy(tmp[0])]
    for i in range(1, 9):
        tmp2.append([])
        for j in range(3):
            k = 0
            while True:
                if len(tmp2[i - 1]) <= k:
                    break
                tmp2[i].append(tmp[i][j] + tmp2[i - 1][k])
                k += 1
    tmp3 =

Submission status: Runtime Error

Solution code:
import numpy as np
import math

s = input()
dg = len(s)

count = 0

if dg < 5:
    for i in range(1,int(s)):
        if set(list(str(i))) == {'7','5','3'}:
            count += 1

    print(count)
else:
    import ipdb; ipdb.set_trace()
    base = (math.factorial(dg-1))/(math.factorial(dg-4)*math.factorial(3)) * (3**(dg-4))
    for i in range(10**dg, int(s)+1):
        if set(list(str(i))) == {'7','5','3'}:
            count += 1
    print(count + base)

Submission status: Runtime Error

Solution code:
a3={'357','375','537','573','735','753'}
def make_a(a,n):
    new_a=set()
    for i in a:
        for j in range(n+1):
            new_a.add(i[:j]+'3'+i[j:])
            new_a.add(i[:j]+'5'+i[j:])
            new_a.add(i[:j]+'7'+i[j:])
    return new_a
a4=make_a(a3,3)
a5=make_a(a4,4)
a6=make_a(a5,5)
a7=make_a(a6,6)
a8=make_a(a7,7)
a9=make_a(a8,8)
a=list(map(int,a3))+list(map(int,a4))+list(map(int,a5))+list(map(int,a6))+list(map(int,a7))+list(map(int,a8))+list(map(int,a9))
n=int(input())
a.append(n)
a.sort()
ans=a.index(n)
if a[ans]==a[ans+1]:
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

base = ["3", "5", "7"]
nums = ["3", "5", "7"]
temp = []
x = 0

while 1:
    for num in nums[(3**x)-1:]:
        for b in base:
            temp.append(b + num)
    nums.extend(temp)
    
    x += 1
    if int(temp[-1]) > 10**9:
        break
    temp = []

target = []
for n in set(nums):
    if "7" in n and "5" in n and "3" in n:
        target.append(int(n))

count = 0
target.sort()
for n in target.:
    if int(n) < N:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
N=int(raw_input())

sum = 0
flag = 0

for i in range(1,N+1):
    flag = 0
#    print str(i)
    nums = set(list(str(i)))
    for n in ['7', '5', '3']:
        if n in nums:
            nums.remove(n)
        else:
            flag = 1
            break
    if len(nums) == 0 and flag ==0:
#        print '!!753num!!'
        sum += 1

print sum

Submission status: Runtime Error

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

def rec(int pref):
	if pref <= n:
		cnt += 1
		for d in {3, 5, 7}:
			rec(pref * 10 + d)


rec(0)
print(cnt - 1)

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
q = deque()
q.append('')
res = set()
while q:
    m = q.pop_front()
    for c in '357':
        if int(m+c) > n: continue
        q.append(m+c)
    for c in '357':
        if c not in m: break
    else:
        res.add(m)
print(len(res))