Farz0l1x

Untitled

Jun 3rd, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. from random import randint
  2. A = [randint(1, 1000) for i in range(1000)]
  3. count = 0
  4. for i in range(len(A)):
  5. for j in range(i + 8, len(A)):
  6. if abs(A[i] - A[j]) % 999 == 0:
  7. count += 1
  8. print(count)
  9.  
  10. k = [0] * 999
  11. count = 0
  12. q = A[:7]
  13. for i in range(7, len(A)):
  14. x = A[i]
  15. ost = x % 999
  16. count += k[ost]
  17. k[q[0] % 999] += 1
  18. q.append(x)
  19. q.pop(0)
  20. print(count)
Advertisement
Add Comment
Please, Sign In to add comment