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 numpy as np

n = int(input())
max_n = int(n ** 0.5)
memo = np.zeros((max_n, max_n, max_n))

ans = [0]*(n+1)

for x in range(1, max_n):
    for y in range(1, max_n):
        for z in range(1, max_n):
            s = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if s < n+1:
                ans[s] += 1


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

Submission status: Accepted

Solution code:
import math


def pattern(x, y, z):
    if x == y == z:
        return 1
    elif x != y and y != z and x != z:
        return 6
    else:
        return 3


def check(ans):
    cnt = 0
    upper = int(math.sqrt(ans))
    for x in range(1, upper):
        if pow(x, 2) > ans:
            break
        for y in range(x, upper):
            if pow(x+y, 2) > ans:
                break
            for z in range(y, upper):
                tmp = x*(x+y+z) + y*(y+z) + z*z
                # tmp = pow(x+y+z, 2) - x*(y+z) - y*z
                if tmp == ans:
                    cnt += pattern(x, y, z)
                    if x == y and y == z and z == x:
                        print(cnt)
                        return
                elif tmp > ans:
                    break
    print(cnt)


N = int(input())
# x^2 + y^2 + z^2 + x*y + y*z + z*x = n

for i in range(1, N+1):
    # upper_value = int(math.sqrt(i))
    check(i)

Submission status: Accepted

Solution code:
from itertools import combinations_with_replacement
def f(N):
    global table
    for x, y, z in combinations_with_replacement(range(1, 100), 3):
        n = x**2+y**2+z**2+x*y+y*z+z*x
        if n>N:
            continue
        if x==y==z:
            table[n] += 1
        elif x==y or y==z or z==x:
            table[n] += 3
        else:
            table[n] += 6
N = int(input())
table = [0 for _ in range(N+1)]
f(N)
for n in range(1, N+1):
    print(table[n])

Submission status: Accepted

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
#=================================================
n=int(input())
F=[0]*(2*10**5+1)
for x in range(1,145):
    for y in range(1,145):
        for z in range(1,145):
            F[x**2+y**2+z**2+x*y+y*z+x*z]+=1

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

Submission status: Accepted

Solution code:
N = int(input())
li = [0]*(pow(10,6))
max_ = int(N**(1/2))+1

from itertools import combinations_with_replacement

for i in combinations_with_replacement(range(1,max_),3):
    a,b,c = i
    sum_ = a**2+b**2+c**2 + a*b+b*c+c*a
    if sum_>N:
        continue

    if a==b==c:
        li[sum_]+=1
    elif (not a==b) and (not b==c) and (not c==a):
        li[sum_]+= 6
    else:
        li[sum_]+= 3
    
for i in range(1,N+1):
    print(li[i])

Submission status: Accepted

Solution code:
import sys
import numpy as np

N = int(input())

o = [0] * (N+1)
for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            n = int( ((i+j) * (j+k)) + i*i + k*k)
            if n < (N+1):
                o[n] += 1
            if n > 10001:
                break

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    dp=[0]*(10000+1)
    for x in range(1,101):
        for y in range(1, 101):
            for z in range(1, 101):
                num = x**2+y**2+z**2+x*y+y*z+z*x
                if num <= 10000:
                    dp[num] += 1
    [print(dp[i]) for i in range(1,n+1)]

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [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+1:
                A[i] += 1
for i in range(1, N+1):
    print(A[i])

Submission status: Accepted

Solution code:
n = int(input())
N = 10 ** 4

l = [0 for _ in range(N + 1)]

for i in range(1, 42):
    for k in range(1, 99):
        for j in range(i, k+1):
            s = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if s > N:
                continue
            d = len(set([i, j, k]))
            if d == 3:
                l[s] += 6
            elif d == 2:
                l[s] += 3
            elif d == 1:
                l[s] += 1

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