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: Wrong Answer

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(numberof753(int(input())))

Submission status: Wrong Answer

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 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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def next_set(nums, digit):
    r = set()
    for num in nums:
        for v in ["3", "5", "7"]:
            r.add(v+num)            
            for i in range(1,len(num)):
                n = list(num)
                n.insert(i, v)
                r.add("".join(n))
            r.add(num+v)
    return r


nums = set(["357", "375", "537", "573", "735", "753"])
s = int(input())

if len(str(s)) < 3:
    print(0)
else:
    count = sum(int(num)<s for num in nums)
    for i in range(len(str(s)) - 3):
        nums = next_set(nums, i+4)
        count += sum(int(num)<s for num in nums)
    print(count)

Submission status: Wrong Answer

Solution code:
a=int(input())

count=0
c=[]
for i in range(1,a,2):
	if str(3) in str(i) and str(5) in str(i) and str(7) in str(i):
		i=str(i).replace("0","")
		i=str(i).replace("1","")
		i=str(i).replace("2","")
		i=str(i).replace("4","")
		i=str(i).replace("6","")
		i=str(i).replace("8","")
		i=str(i).replace("9","")
		if i not in c:
			c.append(i)
			count=count+1
print(count)

Submission status: Wrong Answer

Solution code:

N = int(input())

if int(str(N)[0]) < 3:
    M = len(str(N))-1
    if M<=2:
        ans=0
    else:
        ans = 3**M - 3*(2**M)+3
elif int(str(N)[0]) < 5:
    M = len(str(N))-1
    if M<=2:
        ans=0
    else:
        ans = 2*(3**M - 3*(2**M)+3)
elif int(str(N)[0]) < 7:
    M = len(str(N))-1
    if M<=2:
        ans=0
    else:
        ans = 3*(3**M - 3*(2**M)+3)
else:
    M = len(str(N))
    if M<=2:
        ans=0
    else:
        ans = 3**M - 3*(2**M)+3
print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())

if int(str(N)[0]) < 3:
    M = len(str(N))-1
    if M<=2:
        ans=0
    else:
        ans = 3**M - 3*(2**M)+3
elif int(str(N)[0]) < 5:
    M = len(str(N))-1
    if M<=2:
        ans=0
    else:
        ans = 2*(3**M - 3*(2**M)+3)
elif int(str(N)[0]) < 7:
    M = len(str(N))-1
    if M<=2:
        ans=0
    else:
        ans = 3*(3**M - 3*(2**M)+3)
else:
    M = len(str(N))
    if M<=2:
        ans=0
    else:
        ans = 3**M - 3*(2**M)+3

Submission status: Wrong Answer

Solution code:
def num_357(ls, i, num_l):
    l = ["3", "5", "7"]
    if i > 0:
        for c in l:
            i -= 1
            ls.append(c)
            num_l.append("".join(ls))
            num_357(ls, i, num_l)
            ls.pop(-1)
            i += 1
    else:
        return

num_l = []
ls = []
i =9 

num_357(ls, i, num_l)
num_new = []
for l in num_l:
    if "3" in l and "5" in l and "7" in l:
        num_new.append(int(l))

N = int(input())
num_new.append(N)
print(sorted(num_new).index(N))

Submission status: Wrong Answer

Solution code:
import itertools
x = int(input())
l = [3, 5, 7]


cnt = 0
for i in range(2, len(str(x))+1):
    for v in itertools.combinations_with_replacement(l, i):
        #print(v)
        if (3 in v and 5 in v and 7 in v):
            num = ""
            for text in v:
                num += str(text)
            anagram_list = [''.join(v) for v in itertools.permutations(num)]
            anagram_list =  list(set(anagram_list))
            #print (anagram_list)
            for hoge in anagram_list:
                if int(hoge) < x:
                    cnt += 1
                    #print(hoge)

print (cnt)

Submission status: Wrong Answer

Solution code:
def rest(length):
    c = 0
    for i in range(3,length+1):
        c += 3**i-3*(2**i)+3
    return c


def s(n):
    if n=='': return None
    if int(n) < 100:
        return 0
    head = n[0]
    tail = n[1:]
    length = len(tail)
    if head <'3':
        return rest(length)
    elif head == "3":
        return s3(tail) + rest(length)
    elif head =="4":
        return 3**length-2*2**length+1 + rest(length)
    elif head =="5":
        return s5(tail) + 3**length-2*2**length+1 + rest(length)
    elif head == "6":
        return 2*(3**length-2*2**length+1) + rest(length)
    elif head == '7':
        return s7(tail)+2*(3**length-2*2**length+1) + rest(length)
    else:
        return 3*(3**length-2*2**length+1) + rest(length)#

def s3(n):
    if n=='': return None
    if int(n) < 10:
        return 0
    head = n[0]
    tail = n[1:]
    length = len(tail)
    if head <'3':
        return 0
    elif head == "3":
        return s3(tail)
    elif head =="4":
        return 3**length-2*2**length+1
    elif head =="5":
        return s35(tail) + 3**length-2*2**length+1
    elif head == "6":
        return (3**length-2*2**length+1)+(3**length-2**length)
    elif head == '7':
        return s37(tail)+(3**length-2*2**length+1)+(3**length-2**length)
    else:
        return (3**length-2*2**length+1)+2*(3**length-2**length)#

def s5(n):
    if n=='': return None
    if int(n) < 10:
        return 0
    head = n[0]
    tail = n[1:]
    length = len(tail)
    if head <'3':
        return 0
    elif head == "3":
        return s35(tail)
    elif head =="4":
        return 3**length-2**length
    elif head =="5":
        return s5(tail) + 3**length-2**length
    elif head == "6":
        return (3**length-2*2**length+1)+(3**length-2**length)
    elif head == '7':
        return s57(tail)+(3**length-2*2**length+1)+(3**length-2**length)
    else:
        return (3**length-2*2**length+1)+2*(3**length-2**length)#
def s7(n):
    if n=='': return None
    if int(n) < 10:
        return 0
    head = n[0]
    tail = n[1:]
    length = len(tail)
    if head <'3':
        return 0
    elif head == "3":
        return s37(tail)
    elif head =="4":
        return 3**length-2**length
    elif head =="5":
        return s57(tail) + 3**length-2**length
    elif head == "6":
        return 2*(3**length-2**length)
    elif head == '7':
        return s7(tail)+2*(3**length-2**length)
    else:
        return (3**length-2*2**length+1)+2*(3**length-2**length)#

def s35(n):
    if n=='': return None
    if int(n) < 10:
        return (1 if int(n) >= 7 else 0)
    head = n[0]
    tail = n[1:]
    length = len(tail)
    if head <'3':
        return 0
    elif head == "3":
        return s35(tail)
    elif head =="4":
        return 3**length-2**length
    elif head =="5":
        return s35(tail) + 3**length-2**length
    elif head == "6":
        return 2*(3**length-2**length)
    else:
        return 3**length+2*(3**length-2**length)#

def s37(n):
    if n=='': return None
    if int(n) < 10:
        return (1 if int(n) >= 5 else 0)
    head = n[0]
    tail = n[1:]
    length = len(tail)
    if head <'3':
        return 0
    elif head == "3":
        return s37(tail)
    elif head =="4":
        return 3**length-2**length
    elif head =="5":
        return 3**length + 3**length-2**length
    elif head == "6":
        return 3**length + 3**length-2**length
    else:
        return 3**length+2*(3**length-2**length)#

def s57(n):
    if n=='': return None
    if int(n) < 10:
        return (1 if int(n) >= 3 else 0)
    head = n[0]
    tail = n[1:]
    length = len(tail)
    if head <'3':
        return 0
    elif head == "3":
        return 3**length
    elif head =="4":
        return 3**length
    elif head =="5":
        return 3**length + s57(tail)
    elif head == "6":
        return 3**length + 3**length-2**length
    else:
        return 3**length+2*(3**length-2**length)#

def main():
    n = input()
    print(s(n))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
x = int(input())
l = [3, 5, 7]


cnt = 0
for i in range(2, len(str(x))+1):
    for v in itertools.combinations_with_replacement(l, i):
        #print(v)
        if (3 in v and 5 in v and 7 in v):
            num = ""
            for text in v:
                num += str(text)
            anagram_list = [''.join(v) for v in itertools.permutations(num)]
            anagram_list =  list(set(anagram_list))
            print (anagram_list)
            for hoge in anagram_list:
                if int(hoge) < x:
                    cnt += 1
                    #print(hoge)

print (cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
list=["357","375","537","573","735","753"]
for i in range(0,50000):
	x=list[i]+"3"
	list.append(x)
	y=list[i]+"5"
	list.append(y)
	z=list[i]+"7"
	list.append(z)
    
	a="3"+list[i]
	list.append(a)
	b="5"+list[i]
	list.append(b)
	c="7"+list[i]
	list.append(c)


list_i=[int(s) for s in list]
list_i.sort()

for i in range(0,50000):
	if n>=list_i[i]:
		ans+=1
      
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
a = int(input())
c = str(a)
b = 0
"""
if (b >= 357):    
    for i in range(357, a):
"""


keta = int (math.log10(a) + 1)
list = []
if a >= 357:
    count = 0
    for i in range(3, keta):
        c = 1
        b = 3
        for j in range(0, i):
            c *= 3
            b *= 2
        list.append(c - b +3)
    start = pow(10, keta - 1) * 3
    while start - 1 <= a:
        start += 1
        flg3 = 0
        flg5 = 0
        flg7 = 0

        if math.floor(start / (pow(10, keta - 1))) == 4:
            start += pow(10, keta - 1)
        if math.floor(start / (pow(10, keta - 1))) == 6:
            start += pow(10, keta - 1)
        if math.floor(start / (pow(10, keta - 1))) == 8:
            break
 
        for j in range(0, keta):
            if (str(start)[j] == "3"):
                flg3 = 1
            elif (str(start)[j] == "5"):
                flg5 = 1
            elif (str(start)[j] == "7"):
                flg7 = 1
            else:
                break
            if (j == keta - 1 and flg3 == 1 and flg5 == 1 and flg7 == 1):
                count += 1
                
    b = count + sum(list)
print(b)

Submission status: Wrong Answer

Solution code:
from collections import deque
import bisect
N=int(input())
D=deque()
L=["3","5","7"]
#ans3
i1=0
i2=0
i3=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            s=L[i1]+L[i2]+L[i3]
            if "3" in s and "5" in s and "7" in s:
                D.append(int(s))
i1=0
i2=0
i3=0
i4=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                s=L[i1]+L[i2]+L[i3]+L[i4]
                if "3" in s and "5" in s and "7" in s:
                    D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]
                    if "3" in s and "5" in s and "7" in s:
                        D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]
                        if "3" in s and "5" in s and "7" in s:
                            D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]
                            if "3" in s and "5" in s and "7" in s:
                                D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
i8=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            for i8 in range(3):
                                s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]+L[i8]
                                if "3" in s and "5" in s and "7" in s:
                                    D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
i8=0
i9=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            for i8 in range(3):
                                for i9 in range(3):
                                    s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]+L[i8]+L[i9]
                                    if "3" in s and "5" in s and "7" in s:
                                        D.append(int(s))
d=list(D)
d.sort()
print(bisect.bisect_left(d,N))

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
list=["357","375","537","573","735","753"]
for i in range(0,50000):
	x=list[i]+"3"
	list.append(x)
	y=list[i]+"5"
	list.append(y)
	z=list[i]+"7"
	list.append(z)
    
	a="3"+list[i]
	list.append(a)
	b="5"+list[i]
	list.append(b)
	c="7"+list[i]
	list.append(c)


list_i=[int(s) for s in list]
list_i.sort()

for i in range(0,50000):
	if n>list_i[i]:
   		ans+=1
      
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

d = [7,5,3,7,5,3,7,5,3]

X = int(input())

cnt = 0
e = 0

for i in range(3, len(str(X))+1):
    c = list(itertools.permutations(d, i))
    for j in set(c):
        if str(j).count("3") >= 1 and str(j).count("5") >= 1 and str(j).count("7") >= 1:
            e = int(''.join(map(str, j)))
            if X - e >= 0:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  2 20:06:49 2018

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
"""

N = int(input())

if N < 357:
    print(0)
    sys.exit()
    
data_size = int (math.log10(N) + 1)

N_list = digit(N)
len_N = len(N_list) 
ans_c = 0


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)