Advertisement
Guest User

Untitled

a guest
Mar 18th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | Source Code | 0 0
  1. # https://www.codechef.com/problems/COUNT0110
  2.  
  3. # pattern generator
  4. def f(x):
  5.     possible = set()
  6.     for mask in range(1 << x):
  7.         s = bin(mask)[2:].zfill(x)
  8.         total = [0, 0]
  9.         for i in range(x):
  10.             for j in range(i + 1, x):
  11.                 if s[i] == "0" and s[j] == "1":
  12.                     total[0] += 1
  13.                 elif s[i] == "1" and s[j] == "0":
  14.                     total[1] += 1
  15.         possible.add(tuple(total))
  16.     return len(possible)
  17.  
  18.  
  19. # for i in range(1, 25):
  20. #     print(f(i))
  21.  
  22. # [1, 4, 13, 32, 65, 116, 189, 288, 417, 580, 781][3, 10, 26, 55, 101, 168, 260, 381, 535, 726]
  23.  
  24. from fractions import Fraction
  25.  
  26.  
  27. def solve():
  28.     n = int(input())
  29.     if n % 2 == 1:  # https://oeis.org/search?q=1%2C+4%2C+13%2C+32%2C+65%2C+116%2C+189%2C+288%2C+417%2C+580%2C+781&go=Search
  30.         n //= 2
  31.         n += 1
  32.         print(n * (2 * n ** 2 - 3 * n + 4) // 3)
  33.     else:  # https://oeis.org/search?q=3%2C+10%2C+26%2C+55%2C+101%2C+168%2C+260%2C+381%2C+535%2C+726&go=Search
  34.         # val = 1 + (5 / 6) * n + (1 / 2) * n ** 2 + (2 / 3) * n ** 3
  35.         n //= 2
  36.         val = 1 + Fraction(5, 6) * n + Fraction(1, 2) * n ** 2 + Fraction(2, 3) * n ** 3
  37.         assert val.denominator == 1
  38.         print(val.numerator)
  39.  
  40.  
  41. t = int(input())
  42. for _ in range(t):
  43.     solve()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement