mfgnik

Untitled

Jun 12th, 2020
1,294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def gcd(a, b):
  2.     if b == 0:
  3.         return a
  4.     return gcd(b, a % b)
  5.  
  6.  
  7. n = input()
  8. numbers = list(map(int, input().split()))
  9. max_length = 1
  10. index_first = 0
  11. while index_first + max_length <= len(numbers):
  12.     cur_g = numbers[index_first]
  13.     length = 1
  14.     index_second = index_first + 1
  15.     while cur_g != 1 and index_second < len(numbers):
  16.         cur_g = gcd(cur_g, numbers[index_second])
  17.         numbers[index_second] //= cur_g
  18.         length += cur_g != 1
  19.         index_second += 1
  20.     if length > max_length:
  21.         max_length = length
  22.     index_first += 1
  23. print(max_length)
Advertisement
Add Comment
Please, Sign In to add comment