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
import math

def func(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x

def count_xyz(n):
    counts = np.zeros(n + 1, dtype=int)
    for x in range(1, math.ceil(math.sqrt(n)) + 1):
        if func(x, x, x) > n:
                break
        for y in range(x, math.ceil(math.sqrt(n)) + 1):
            if func(x, y, y) > n:
                    break
            for z in range(y, math.ceil(math.sqrt(n)) + 1):
                if func(x, y, z) > n:
                    break
                if len({x, y, z}) == 1:
                    counts[func(x, y ,z)] += 1
                elif  len({x, y, z}) == 2:
                    counts[func(x, y ,z)] += 3
                else:
                    counts[func(x, y ,z)] += 6
    
    return counts


def main():
    N = int(input())
    counts = count_xyz(N)
    for i in range(1, N + 1):
        print(counts[i])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import combinations, combinations_with_replacement
from math import sqrt


n = int(input())
ans = [0] * (n + 1)
for x, y, z in combinations_with_replacement(range(1, int(sqrt(n))), 3):
    i = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    if i <= n:
        if x == y == z:
            ans[i] += 1
        elif all([(s != t) for s, t in combinations([x, y, z], 2)]):
            ans[i] += 6
        else:
            ans[i] += 3

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

Submission status: Accepted

Solution code:
import math

N = int(input())

for n in range(1, N + 1):
    count = 0
    ub = int(math.sqrt(n))
    for x in range(1, ub + 1):
        for y in range(x, ub + 1):
            r = 4 * n - 3 * x * x - 2 * x * y - 3 * y * y
            if r < 0:
                break
            z = (math.sqrt(r) - x - y) / 2
            if z - int(z) < 1e-9:
                z = int(z)
            elif z - int(z + 1) < 1e-9:
                z = int(z + 1)
            else:
                break

            if y > z or z > ub:
                break
            if abs(x * x + y * y + z * z + x * y + y * z + z * x - n) < 1e-9:
                #print(x, y, round(z), z)
                s = len(set([x, y, round(z)]))
                if s == 1:
                    count += 1
                elif s == 2:
                    count += 3
                else:
                    count += 6

    print(count)

Submission status: Accepted

Solution code:
n=int(input())
ans=[0]*n

for i in range(1,101):
  for j in range(i,101):
    for k in range(j,101):
      if 1<=(i+j+k)**2-(i*j+j*k+k*i)<=n:
        ll=len(set([i,j,k]))
        if ll==1:
          aa=1
        elif ll==2:
          aa=3
        else:
          aa=6
        ans[(i+j+k)**2-(i*j+j*k+k*i)-1]+=aa
for aa in ans:
  print(aa)

Submission status: Accepted

Solution code:
from numba import jit

N = int(input())

@jit
def f():
    ret = [0] * 10001

    for i in range(1, 200):
        for j in range(1, 200):
            for k in range(1, 200):
                z = i**2 + j**2 + k**2 + i*j + j*k + k*i
                if z < 10001:
                    ret[z] += 1

    return ret


ans = f()

for x in range(1, N+1):
    print(ans[x])

Submission status: Accepted

Solution code:

import math
def func(x,y,z):
    ans = x**2 + y**2 + z**2+ x*y + y*z + z*x
    return ans

N = int(input())
array_N = [0]*N
root_n = round(math.sqrt(N+1))

for x in range(1,root_n):
    for y in range(1,root_n):
        for z in range(1,root_n):
            if func(x,y,z) <= N:
                array_N[func(x,y,z)-1] = array_N[func(x,y,z)-1] +1
                
for i in range(N):
    print(array_N[i])

Submission status: Accepted

Solution code:
n = int(input())
num = [0]*(10**5+1)
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            num[(i**2 + j**2 + k**2 + i*j + j*k + k*i)] += 1
for i in range(1,n+1):
    print(num[i])

Submission status: Accepted

Solution code:
N = int(input())
Xlist = [0]*(10**4)
for i in range(100):
    for j in range (100):
        for k in range(100):
            A = (i + j + 2)**2 + (k + j + 2)**2 + (i + k + 2)**2
            if ((A % 2) == 0)and(A <= 20000):
                Xlist[(A//2 -1)] += 1

for a in range (N):
    print(Xlist[a])

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

def unko(x, y, z):
    return x**2+y**2+z**2+x*y+x*z+y*z

sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
ans = [0]*(N+1)
f=0
#a, b, c = map(int, input().split())
rootN = int(math.sqrt(N))

for i in range(1,rootN):
    for j in range(1, rootN):
        for k in range(1, rootN):
            f=unko(i,j,k)
            if(f>N):
                pass
            else:
                ans[f]+=1
                #if(i==j and j==k):
                    #ans[f]-=2

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