I tried to solve AtCoder's 755 C problem in Python. This is an easy problem to solve using a recursive function.
I referred to an article by Mr. Kencho, who is well known in the Japanese competitive programming world. Reference article: https://drken1215.hatenablog.com/entry/2019/04/03/125400
It's still awkward, so I had a hard time understanding the difference between logical and bitwise operators. Click here for articles that helped me understand these ↓ http://ings.sakura.ne.jp/prog/bitoperator.html
N = int(input())
def func(cur, use, counter):
if cur > N: return
if use == 0b111: counter.append(1) #Increase the answer
#Add 7
func(cur * 10 + 7, use | 0b001, counter)
#Add 5
func(cur * 10 + 5, use | 0b010, counter)
#Add 3
func(cur * 10 + 3, use | 0b100, counter)
res = []
func(0, 0, res)
print(sum(res))
The result looks like this. I was able to AC safely.
Recommended Posts