Advertisement
nq1s788

8 (генерация рекурсией)

Sep 1st, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. #https://inf-ege.sdamgia.ru/problem?id=59746
  2. def gen(s, k):
  3.     global cnt
  4.     if len(s) == k:
  5.         if (int(s) % 5) == 0:
  6.             cnt += 1
  7.         return
  8.     for nxt in range(10):
  9.         if (len(s) == 0) and (nxt == 0):
  10.             continue
  11.         if str(nxt) not in s:
  12.             gen(s + str(nxt), k)
  13.  
  14.  
  15. cnt = 0
  16. for i in range(1, 11):
  17.     gen('', i)
  18. print(cnt + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement