Problem:


Score : 300 points

Problem Statement

Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:

1 \leq x,y,z

x^2 + y^2 + z^2 + xy + yz + zx = n

Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).

Constraints

All values in input are integers.

1 \leq N \leq 10^4

Input

Input is given from Standard Input in the following format:

N

Output

Print N lines. The i-th line should contain the value f(i).

Sample Input 1

20

Sample Output 1

0
0
0
0
0
1
0
0
0
0
3
0
0
0
0
0
3
3
0
0

For n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.

For n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.

For n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.

For n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.



Sample input:
20


Sample output:
0
0
0
0
0
1
0
0
0
0
3
0
0
0
0
0
3
3
0
0

Submission status: Accepted

Solution code:
N = int(input())
import itertools
num = [i for i in range(1,101)]
comb = list(itertools.combinations_with_replacement(num, 3))
cnt_list = [0] * 10001
for c in comb:
    x = c[0]
    y = c[1]
    z = c[2]
    n = x**2 + y**2 + z**2 + x*y + y*z + z*x
    if n <= 10000:
        if x == y and y == z and z == x:
            cnt_list[n] += 1
        elif x == y or y == z or z == x:
            cnt_list[n] += 3
        else:
            cnt_list[n] += 6
for i in range(1,N+1):
    print(cnt_list[i])

Submission status: Accepted

Solution code:
import math

N = int(input())

def xyzTriplets(N):
    store = {}
    upTo = math.sqrt(N)
    for x in range(1, int(upTo) + 1):
        for y in range(1, int(upTo) + 1):
            for z in range(1, int(upTo) + 1):
                res = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
                if (res not in store):
                    store[res] = 1
                else:
                    store[res] += 1
    for i in range(1, N+1):
        if (i in store):
            print(store[i])
        else:
            print(0)



xyzTriplets(N)

Submission status: Accepted

Solution code:
import math
N = int(input())
ans_list = [0 for i in range(N)]
index = int(math.sqrt(N))

for x in range(1,index):
  for y in range(1,index):
    for z in range(1,index):
      n = x**2 + y**2 + z**2 + x*y + y*z + z*x 
      if (n <= N):
        ans_list[n-1] += 1
for i in range(N):
  print(ans_list[i])

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement

N = int(input())
ans = [0] * (N + 1)            

for x, y, z in combinations_with_replacement(list(range(1, 100)), 3):
    val = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + x * z

    n_diff = len(set([x, y, z]))
    if n_diff == 3:
        cnt = 6
    if n_diff == 2:
        cnt = 3
    if n_diff == 1:
        cnt = 1

    # print(val)
    
    if val <= N:
        ans[val] += cnt

print('\n'.join(map(str, ans[1:])))

Submission status: Accepted

Solution code:
N = int(input())
nijo = []
for k in range(2, int((2*N)**0.5) + 1):
  nijo.append(k**2)
nijo = [1] + nijo
count = [0 for _ in range(N)]
for k in range(2, len(nijo) +1):
  for j in range(2, len(nijo)+ 1):
    if nijo[k-1] + nijo[j-1] > 2*N:
      break
    for l in range(2, len(nijo)+1):
      if nijo[k-1] + nijo[j-1] + nijo[l-1] > 2*N:
        break
      elif (nijo[k-1] + nijo[j-1] + nijo[l-1]) %2 == 0:
        if k + l -j > 1 and -k+j+l > 1 and k + j -l >1:
          count[(nijo[k-1] + nijo[j-1] + nijo[l-1])//2-1] += 1

for _ in range(N):        
  print(count[_])

Submission status: Accepted

Solution code:
# C XYZ Triplets

n = int(input())

ans = {}
for x in range(1, 99):
  for y in range(1, 99):
    for z in range(1, 99):
      k = (x+y)**2+(y+z)**2+(z+x)**2
      if k > 20000:
        break
      if k % 2 == 0:
        if not k//2 in ans:
          ans[k//2] = 1
        else:
          ans[k//2] += 1

for i in range(1, n+1):
  if i in ans:
    print(ans[i])
  else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
f = [0] * (N+1)
for x in range(1, int(N ** 0.5)):
    for y in range(x, int(N ** 0.5)):
        for z in range(y, int(N ** 0.5)):
            num = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if num <= N:
                if x == y and y == z:
                    f[num] += 1
                elif x != y and y != z and z != x:
                    f[num] += 6
                else:
                    f[num] += 3
for i in range(len(f)):
    if i == 0:
        continue
    print(f[i])

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.zeros(n)

x, y, z = 1, 1, 1

while x**2 + y**2 + z**2 + x*y + y*z + z*x <= n:
    while x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x <= n:
        while x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x <= n:
            i = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            A[i - 1] += 1
            z += 1
        z = 1
        y += 1
    y, z = 1, 1
    x += 1
for i in range(n):
    print(int(A[i]))

Submission status: Accepted

Solution code:
N = int(input())
A = [0 for i in range(N)]
a = 1
X = 0
while 1:
  X += (a + a - 1)
  if X > N:
    break
  Y = X
  b = 1
  while 1:
    Y += (a + b + b - 1)
    if Y > N:
      break
    Z = Y
    c = 1
    while 1:
      Z += (a + b + c + c - 1)
      if Z <= N:
        A[Z-1] += 1
      else:
        break
      c += 1
    b += 1
  a += 1
for a in A:
  print(a)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    dict={}
    for j in range(1,101):
        for k in range(1,101):
            for l in range(1,101):
                calc = j**2+k**2+l**2 +j*k+k*l+l*j
                if calc in dict:
                    dict[calc]+=1
                else:
                    dict[calc]=1
    for i in range(1,n+1):
        if i in dict:
            print(dict[i])
        else:
            print(0)

Submission status: Accepted

Solution code:
import math
N = int(input())
arr = [0]*N
rtN = int(math.sqrt(N))*2
for x in range(rtN)[1:]:
    for y in range(rtN)[x:]:
        for z in range(rtN)[y:]:
            r = x*x +y*y+z*z+x*y+y*z+z*x
            if r <= N:
                if (x==z):
                    arr[r-1] +=1
                elif(x==y or y==z):
                    arr[r-1] +=3
                else:
                    arr[r-1] +=6
for ar in arr:
	print(ar)

Submission status: Accepted

Solution code:
import collections

l=[]
n=int(input())
for x in range(1,10**2+1):
    if x**2>n:continue
    for y in range(1,10**2+1):
        if x**2+y**2>n:continue
        for z in range(1,10**2+1):
            if x**2+y**2+z**2>n:continue
            l.append(x**2+y**2+z**2+x*y+y*z+z*x)

c=collections.Counter(l)
for x in range(1,n+1):
    print(c[x])

Submission status: Accepted

Solution code:
N = int(input())

ans = [0] * N
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n = x * x + y * y + z * z + x * y + y * z + z * x
            if n <= N:
                ans[n-1] += 1

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())

memo = {}
n = 0

while n < N:
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 100):
                n = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if n > N :
                    break
                memo.setdefault(n, [])
                memo[n].append((x,y,z))

for i in range(1, N+1):
    if i in memo:
        print(len(memo[i]))
    else :
        print(0)

Submission status: Accepted

Solution code:
N=int(input())
ans=[0]*N
for x in range(1,int((N-1)/2)):
    for y in range(x,int((N-1)/2)):
        if x ** 2 + y ** 2 + 1 ** 2 + x * y + y * 1 + 1 * x > N:
            break
        for z in range(y,int((N-1)/2)):
            if x**2+y**2+z**2+x*y+y*z+z*x<=N:
                if x==y and y==z:
                    ans[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1
                elif x==y or y==z or z==x:
                    ans[x**2+y**2+z**2+x*y+y*z+z*x-1]+=3
                else:
                    ans[x**2+y**2+z**2+x*y+y*z+z*x-1]+=6
            else:
                break

for n in range(N):
    print(ans[n])

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  ans = []
  flg = 1
  for i in range(1,n+1):
    flg = 1
    anstmp = 0
    for x in range(1,int(i**0.5+1)):
      if flg == 0:
        break
      for y in range(x,int(i**0.5+1)):
        if i-(x**2+y**2+x*y) > x+y:
          j = i-(x**2+y**2+x*y)
          z = int((j+(x+y)**2/4)**0.5-(x+y)/2+0.5)
          if (x+y+z)*z == j:
            if x < y:
              anstmp += 2
            else:
              anstmp += 1
        elif y == 1:
          flg = 0
          break
        else:
          break
    ans.append(anstmp)
  print(*ans,sep="\n")
main()

Submission status: Accepted

Solution code:
ar = [0 for a in range(10001)]
for a in range(1,100):
    for b in range(1,100):
        for c in range(1,100):
            if a*a + b*b + c*c +a*b + b*c + c*a <=10**4:
                ar[a*a + b*b + c*c +a*b + b*c + c*a]+=1

n = int(input())
for i in range(1,n+1):
    print(ar[i],end= " ")

Submission status: Accepted

Solution code:
N = int(input())
f = [0]*10000001

for i in range(1,101):
	for j in range(i,101):
		for k in range(j,101):
			n = i**2+j**2+k**2+i*j+j*k+k*i
			if i == j == k:
				f[n] += 1
			elif (i == j and j != k) or (i != j and j == k):
				f[n] += 3
			else:
				f[n] += 6

for i in range(1,N+1):
	print(f[i])

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N
for x in range(1,N):
    for y in range(1,N):
        if x**2 + y**2 + x*y > N:
            break
        for z in range(1,N):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if s>N:
                break
            A[s-1] = A[s-1]+1
for i in range(N):
    print(A[i])

Submission status: Accepted

Solution code:
N = int(input())
t = 1
if N > 1:
    t = int((N-2)**0.5)
ans = [0]*(N+1)
for i in range(1,t):
    for j in range(1,i+1):
        for k in range(1,j+1):
            a = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if a > N:
                continue
            t = 1
            if (i == j and j > k) or (i>j and j==k):
                t = 3
            elif i > j and j > k:
                t = 6
            ans[a] += t
for i in range(1,N+1):
    print(ans[i])

Submission status: Accepted

Solution code:
N = int(input())
Ali = [0]*(N+1)
 
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      i = x**2+y**2+z**2+x*y+y*z+z*x
      if i<=N:
        Ali[i] += 1
        
for i in range(N):
  print(Ali[i+1])

Submission status: Accepted

Solution code:
import math
N = int(input())
A = [0 for _ in range(N)]
for x in range(1,math.floor(N**0.5)+1):
    for y in range(1,math.floor((N-x**2)**0.5)+1):
        for z in range(1,math.floor((N-x**2-y**2)**0.5)+1):
            c = x**2+y**2+z**2+x*y+y*z+z*x
            if c <= N:
                A[c-1] += 1
for i in range(N):
    print(A[i])

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


def func(a, b, c):
    return a * a + b * b + c * c + a * b + b * c + c * a


n = inp()
limit = int(math.sqrt(n)) + 1
ans = [0] * n
for i in range(1, limit):
    for j in range(i, limit):
        for k in range(j, limit):
            x = func(i, j, k) - 1
            if x < n:
                if len(set([i, j, k])) == 1:
                    ans[x] += 1
                elif len(set([i, j, k])) == 2:
                    ans[x] += 3
                elif len(set([i, j, k])) == 3:
                    ans[x] += 6
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import math

n = int(input())

ans = [0] * n

r = math.floor(math.sqrt(n))
for x in range(1,r+1):
  for y in range(x,r+1):
    for z in range(y,r+1):
      sum = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if sum <= n:
        if x == y and y == z:
          ans[sum-1] += 1
        elif x == y or y == z or z == x:
          ans[sum-1] += 3
        else:
          ans[sum-1] += 6

for p in ans:
  print(p)

Submission status: Accepted

Solution code:
import numpy as np
def resolve():
    N = int(input())
    Nlist = np.zeros(N + 1,dtype =  int)
    for i in range(1,100):
        for j in range(1,100):
            for k in range(1,100):
                num = i*i + j*j + k*k + i*k + i*j + j*k
                if num > N :
                    break
                else:
                    Nlist[num] += 1
    for i in range(1,N+1):
        print(Nlist[i])
resolve()

Submission status: Accepted

Solution code:
def main():
    n = int(input())

    A = [0] * (10 ** 6)
    for x in range(1, 10 ** 2 + 1):
        for y in range(1, 10 ** 2 + 1):
            for z in range(1, 10 ** 2 + 1):
                i = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x
                A[i] += 1

    for i in range(1, n + 1):
        print(A[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def f(x, y, z):
    return x*x + y*y + z*z + x*y + y*z + z*x
    
N = int(input())

ans = {}
for x in range(1, 100):
    for y in range(1, x+1):
        for z in range(1, y+1):
            ret = f(x, y, z)
            delta = 0
            if ret <= N:
                if x == y and y == z:
                    delta = 1
                elif x != y and y != z and z != x:
                    delta = 6
                else:
                    delta = 3
            
                if ret not in ans:
                    ans[ret] = delta
                else:
                    ans[ret] += delta

for i in range(1, N+1):
    if i in ans:
        print(ans[i])
    else:
        print(0)

Submission status: Accepted

Solution code:
n = int(input())

ans = [0 for i in range(n)]
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            k = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if k <= n:
                ans[k-1] += 1
for i in range(n):
    print(ans[i])