zhukov000

Примеры программ

Oct 5th, 2021
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. Задание 2:
  2.  
  3. print('x y z w')
  4. for x in 0,1:
  5.   for y in 0,1:
  6.     for z in 0,1:
  7.       for w in 0,1:
  8.         f = (not(y <= (x == w))) and (z <= x)
  9.         if f == 1:
  10.           print(x, y, z, w)
  11.          
  12.          
  13. Задача 4:
  14. bin(123) - перевод в 2ю систему счисления
  15. oct(123) - перевод в 8ю систему счисления
  16. hex(123) - перевод в 16ю систему счисления
  17. int('10101', 2) - перевод из 2й в 10ю
  18. int('10101', 5) - перевод из 5й в 10ю
  19.  
  20. Задача 6:
  21. for i in range(1, 10000):
  22.   s = i # int(input())
  23.   s = s // 10
  24.   n = 1
  25.   while s < 51:
  26.     s = s + 5
  27.     n = n * 2
  28.   # print(n)
  29.   if n == 64:
  30.     print(i)
  31.  
  32. Задача 8:
  33. # from math import factorial
  34. from itertools import permutations, product
  35.  
  36. n = 1
  37. for t in product("ЕЛМРУ", repeat=4):
  38.   st = "".join(t)
  39.   if st[0] == "Л":
  40.     print(n)
  41.     break
  42.   n += 1
  43.  
  44. Задача 12:
  45. s = "8" * 70
  46. while "2222" in s or "8888" in s:
  47.   if "2222" in s:
  48.     s = s.replace("2222", "88", 1) # заменить 1 раз
  49.   else:
  50.     s = s.replace("8888", "22", 1)
  51. print(s)
  52.  
  53. Задача 14:
  54. n = 3 * 4**38 + 2 * 4**23 + 4**20 + 3*4**5 + 2 * 4**4 + 1
  55. p = 16
  56. k = 0
  57. while n > 0:
  58.   d = n % p
  59.   if d == 0:
  60.     k += 1
  61.   n = n // p
  62. print(k)
  63.  
  64. Задача 16:
  65. def F(n):
  66.   if n == 1:
  67.     return 1
  68.   if n % 2 == 0:
  69.     return n + F(n - 1)
  70.   return 2 * F(n - 2)
  71.  
  72. print(F(26))
  73.  
  74.  
  75. Задача 17:
  76. n = 5000
  77. a = []
  78. for i in range(n):
  79.   x = int(input())
  80.   a.append(x)
  81.  
  82. k = 0
  83. mx = -20000
  84. for i in range(1, n):
  85.   if a[i-1] % 3 == 0 or a[i] % 3 == 0:
  86.     k += 1
  87.     if (a[i-1] + a[i]) > mx:
  88.       mx = a[i-1] + a[i]
  89. print(k, mx)
  90.  
  91. Задача 23:
  92.  
  93. def F(a, b):
  94.   if a == b:
  95.     return 1
  96.   if a > b:
  97.     return 0
  98.   return F(a+1,b) + F(a*2,b)
  99.  
  100. print(F(1,10) * F(10,20))
  101.  
  102.  
  103.  
  104.  
  105.  
Advertisement
Add Comment
Please, Sign In to add comment