Advertisement
nq1s788

5 (троичная система)

Jan 12th, 2025
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. # 5й номер https://kpolyakov.spb.ru/school/ege/gen.php?action=viewVar&answers=on&varId=7
  2. answ = 10000000000
  3. for x in range(1, 100000):
  4.     cur = x
  5.     s = ''
  6.     while cur != 0:
  7.         s += str(cur % 3)
  8.         cur //= 3
  9.     s = s[::-1]
  10.     if x % 2 == 0:
  11.         s = '2' + s
  12.         if s[-1] == '0':
  13.             s += '0'
  14.         elif s[-1] == '1':
  15.             s += '2'
  16.         else:
  17.             s += '11'
  18.     else:
  19.         s += '2'
  20.         if s[0] == '0':
  21.             s = '0' + s
  22.         elif s[0] == '1':
  23.             s = '2' + s
  24.         else:
  25.             s = '11' + s
  26.     dec = 0
  27.     for i in range(len(s)):
  28.         dec += int(s[i]) * 3 ** (len(s) - i - 1)
  29.     if dec > 100:
  30.         answ = min(answ, dec)
  31. print(answ)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement