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:
import math
N = int(input())
fn_array = [0] * 60000
for x in range(1, 100):
    for y in range(1, x + 1):
        for z in range(1, y + 1):
            n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if x == y and y == z:
                fn_array[n] += 1
            elif (x == y) and (y != z):
                fn_array[n] += 3
            elif (x != y) and (y == z):
                fn_array[n] += 3
            else:
                fn_array[n] += 6
for n in range(1, N+1):
    print(fn_array[n])

Submission status: Accepted

Solution code:
# import sys
import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    ans = [0 for i in range(n+1)]
    for i in range(1,int(n**0.5)+1):
        for j in range(1,int(n**0.5)+1):
            for k in range(1,int(n**0.5)+1):
                a = i**2+j**2+k**2+i*j+j*k+i*k
                if a<=n:
                    ans[a] += 1
    for i in range(1,n+1):
        print(ans[i])
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
from numba import njit

@njit('i8(i8)', cache=True)
def fun(n):
    #mx = n#int((n**.5) // 3) + 1
    mx = int(n**.5 + 0.5)
    pairs = 0
    for x in range(1, mx + 1):
        for y in range(x, mx + 1):
            for z in range(y, mx + 1):
                v = x*x + y*y + z*z + x*y + y*z + z*x
                if v == n:
                    if x == y == z:
                        pairs += 1
                    elif x == y or y == z:
                        pairs += 3
                    else:
                        pairs += 6
    return pairs

n = int(input())
for i in range(n):
    ps = fun(i + 1)
    print(ps)

Submission status: Accepted

Solution code:
n = int(input())
#print(n)

ptn = [0 for _ in range(20000)]


for x in range(1, 125):
    for y in range(1, 125):
        for z in range(1, 125):
            if x+y+z <= 125:
                ptn[x**2 + y**2 + z**2 + x*y + y*z + x*z] += 1

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

Submission status: Accepted

Solution code:
from math import sqrt
N = int(input())
if N == 1:
    print(0)
    import sys
    sys.exit()
ans = [0] * (N+1)
x = int(sqrt(N-2))+1
for j in range(1, x):
    for k in range(1, x):
        for l in range(1, x):
            y = j**2+k**2+l**2+j*k+k*l+l*j
            if y <= N:
                ans[y] += 1
for n in ans[1:N+1]:
    print(n)

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(300):
  l.append(i**2)
l=set(l)
for i in range(1,n+1):
  ct=0
  for j1 in range(1,int(n**0.5)+2):
    for j2 in range(1,int(n**0.5)+2):
      a=j1+j2
      b=i-j1**2-j2**2-j1*j2
      if a**2+4*b in l:
        k=int((a**2+4*b)**0.5)
        if (a+k)%2==0:
          j3=(-a+k)//2
          if j3>0:
            ct+=1
  print(ct)