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: Time Limit Exceeded

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    N = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    for n in range(1,N+1):
        ans = 0
        for x in range(1,int(n**0.5)+1):
            for y in range(1,int(n**0.5)+1):
                pre = x**2 + y**2 + x*y
                uu = n-pre
                if uu<0:
                    break
                for z in range(1,int(uu**0.5)+1):
                    if z*(z+x+y)==uu:
                        if len(set([x,y,z])) == 1:
                            ans = 1
                            break
                        elif len(set([x,y,z])) == 2:
                            ans = 3
                            break
                        else:
                            ans = 6
                            break
        print(ans)



if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
if n<=5:
  for i in range(n):
    print(0)
else:
  for i in range(5):
    print(0)
for i in range(6, n+1):
  count=0
  for x in range(1, i):
    for y in range(1, i):
      for z in range(1, i):
        """print(x,y,z)
        print(x*x + y*y + z*z+ x*y + y*z + z*x)
        print(i)"""
        if x*x + y*y + z*z + x*y + y*z + z*x == i:
          count+=1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
def f(i):
  co=0
  for z in range(1,8):
    for y in range(1,8):
      for x in range(1,8):
        if x**2+y**2+z**2+z*y+z*x+y*x==i:
          co+=1
        if x**2+y**2+z**2+z*y+z*x+y*x>i:
          break
  return co
for i in range(1,n+1):
  print(f(i))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n=int(input())

a=[0]*(n+1)
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            for l in range(1,n+1):
                if j**2+k**2+l**2+j*k+k*l+l*j==i:
                    a[i]+=1

for x in range(1,n+1):
    print(a[x])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

for i in range(1,n+1):
    ans=0
    for x in range(1,i+1):
        if x>=i:
            break
        for y in range(1,i+1):
            if x*y >= i:
                break
            else:
                for z in range(1,i+1):
                    if x**2+y**2+z**2+x*y+y*z+z*x==i:
                        ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:


n=int(input());

for i in range(1,n+1):
	ct=0;
	for x in range(1,32):
		for y in range(1,32):
			for z in range(1,32):
				j=(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
				if j==i:
					ct+=1; 

	print(ct)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())

def judge(n, x=1, y=1, z=1, l=[]):
    num = 0
    result = x**2 + y**2 + z**2 + x*y + y*z + z*x
    x_th = int(math.sqrt(n))+1
    for x_i in range(x, x_th+1):
        #print('x_i: ', x_i)
        for y_i in range(x_i, x_th+1):
            y_th = n - x_i**2 + y_i**2 + x_i*y_i
            #print('y_i: ', y_i)
            #print('y_th: ', y_th)
            if y_th < 0:
                break
            for z_i in range(y_i, x_th):
                #print('z_i: ', z_i)
                result = x_i**2 + y_i**2 + z_i**2 + x_i*y_i + y_i*z_i + z_i*x_i
                #print('result: ', result)
                if result > n:
                    break
                elif result == n:
                    if x_i != y_i != z_i:
                        num += 6
                    elif x_i == y_i != z_i or x_i != y_i == z_i:
                        num += 3
                    elif x_i == y_i == z_i:
                        num += 1
    return num

#fn = judge(6, l=[])
#print(fn)
for i in range(1, n+1):
    fn = judge(i, l=[])
    print(fn)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

for f in range(1, n+1):
    ans = 0
    for x in range(1, n+1):
        for y in range(1, n+1):
            for z in range(1, n+1):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == f:
                    ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
nn = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))
#nn = 10**4
ans_L = []
for n in range(1,nn+1):
    ans = 0
    for x in range(1,41):
        for y in range(1,41):
            for z in range(1,41):
                if x**2 + y**2 + z**2 + x*y + y*z + x*z == n:
                    ans += 1

    ans_L.append(ans)

for i in ans_L:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
for n in range(1, N+1):
    # count number of sets (x, y,x)
    #assume x<y<z
    ans=0
    z_low=int((n/6)**0.5)
    z_up=int(n**0.5)
    for z in range(z_low, z_up):
        if (n-3*z**2)/3 <=0:
            y_low=1
        else:
            y_low=int(((n-3*z**2)/3)**0.5)
        for y in range(y_low, z+1):
            if n-3*z**2-2*y**2<=0:
                x_low=1
            else:
                x_low=int((n-3*z**2-2*y**2)**0.5)
            for x in range(x_low, int((n/6)**0.5)+1):
                if n == x**2 + y**2 + z**2 + x*z + x*y + y*z:
                    # classify
                    if x==y and x==z:
                        #x=y=z
                        ans+=1
                    elif x==y and x!=z:
                        ans+=3
                    elif y==z and y != x:
                        ans+=3
                    elif z==x and z!=y:
                        ans+=3
                    else:
                        ans+=6
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
for i in range(1,n+1):
    c = 0
    total = n
    while 1:
        for x in range(1,i//2):
            for y in range(x,i//2):
                for z in range(y,i//2):
                    total = ((x+y)**2 + (z+y)**2 + (x+z)**2) / 2
                    if total == i:
                        if x==y==z:
                            c += 1
                        elif x ==y or y == z:
                            c += 3
                        else:
                            c += 6
                        break
                    elif total>i:
                        break
        if total>i:
            break
    print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

for i in range(1, N+1):
    count = 0
    for x in range (1, i):
        for y in range(1, i):
            for z in range(1, i):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = []
for n in range(1,N+1):
    result = 0
    for x in range(1,int(n**(1/2))+1):
        if x**2 < n:
            for y in range(1,int(n**(1/2))+1):
                if x**2+y**2 < n:
                    for z in range(1,int(n**(1/2))+1):
                        if x**2+y**2+z**2+x*y+y*z+z*x==n:
                            result += 1
    ans += [result]

print("\n".join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
import sys
N=int(input())
for n in range(1,N+1):
    count=0
    for x in range(1,n+1):
        for y in range(1,n-x):
            for z in range(1,n-x-y):
                if x**2+y**2+z**2+x*y+y*z+z*x==n:
                    count=count+1
                else:
                    count=count
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())

def calc(n):
  ret = 0
  if n < 6:
    return 0
  else:
    n_sqrt = math.floor(math.sqrt(n))
    for x in range(1,n_sqrt):
      for y in range(1,n_sqrt):
        for z in range(1,n_sqrt):
          if (x*x + y*y + z*z + x*y + y*z + z*x) == n:
            ret += 1
    
    return ret

for i in range(N):
  print(calc(i+1))

Submission status: Time Limit Exceeded

Solution code:

N = int(input())

def func(N):
    count = 0
    for x in range(1, 100):
      for y in range(1, 100):
          D = (x+y)**2 -4*(x**2 + y**2+ x*y - N)
          if D > 0:
              z = -(x+y)/2 + D**0.5 / 2
              if z.is_integer() and z >= 1:
                  count += 1
    return count
  
  
for n in range(1,N+1):
  print(func(n))

Submission status: Time Limit Exceeded

Solution code:
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N = II()

    for i in range(1,N+1):
        if i < 3:
            print(0)
        else:
            ans = 0
            x_max = int((i-2)**0.5-1)
            for x in range(1, x_max+1):

                for y in range(x, x_max+2):
                    xy = x*x+y*y+x*y
                    if i>xy:
                        z_max = int((i-xy)**0.5)

                        for z in range(y, z_max+1):
                            if xy+z*z+y*z+z*x == i:
                                setnum = len(set([x,y,z]))
                                if setnum == 1:
                                    ans += 1
                                elif setnum == 2:
                                    ans += 3
                                elif setnum == 3:
                                    ans += 6
            
            print(ans)


if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
import math
n = input()
N = int(n)
for i in range(1,N+1):
    ans = 0
    for x in range(1,math.floor(i**0.5)):
        lis = [x+1,i-x**2]
        for y in range(1, min(lis)):
            lis2 =[y+1, i-x**2-y**2]
            for z in range(1,min(lis2)):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x ==i:
                    s = {x, y, z}
                    for k in range(len(s)):
                        ans+= (k+1)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def equation(a, b, c):
    D = (b**2 - 4*a*c) ** (1/2)
    x_1 = (-b + D) / (2 * a)
    x_2 = (-b - D) / (2 * a)

    return x_1, x_2



def main():
    N = int(input())

    for n in range(1, N+1):
        cnt = 0
        for y in range(1, n):
            for z in range(1, n):
                x_1, x_2 = equation(1, y+z, y**2 + y*z + z**2 - n)

                if isinstance(x_1, float):
                    x_1 = round(x_1, 5)
                    if x_1.is_integer() == True and x_1 >= 1:
                        cnt += 1

                if isinstance(x_2, float):
                    x_2 = round(x_2, 5)
                    if x_2.is_integer() == True and x_2 >= 1:
                        cnt += 1

        print(cnt)




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())

value_array = []
for x in range(1, int(math.sqrt(N))):
  for y in range(1, int(math.sqrt(N))):
    for z in range(1, int(math.sqrt(N))):
      value_array.append(x**2 + y **2 + z ** 2 + x*y + y*z + z*x)

[print(value_array.count(i)) for i in range(1, N+1)]

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
for i in range(n):
  if (i+1) < 6:
    print(0)
  else:
    count=0
    for j in range(100):
      for k in range(100):
        c= ((j+1)+(k+1))**2-4*((j+1)**2+(k+1)**2+(j+1)*(k+1)-(i+1))
        
        if c > 0:
          z = -(j+k+2)+c**(1/2)
        if z.is_integer() and z%2 == 0 and z>0:
          count +=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

n = int(input())
prod = list(product(list(range(1, n)), repeat=3))

for num in range(1, n+1):
    count = 0
    
    for i in prod:
        x = i[0]
        y = i[1]
        z = i[2]

        if x**2 + y**2 + z**2 +x*y + y*z + z*x == num:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
for i in range(1,n+1):
    ans = 0
    for x in range(40):
        for y in range(40):
            for z in range(40):
                if (x+y+z)**2 -(x*y+y*z+z*x) == i and x>=1 and y>=1 and z>=1:
                    ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

for i in range(1,N+1):
    count=0
    for x in range(1,int(i**0.5)):
        for y in range(1,N-x**2):
            a=-(y+x)
            b=(y*x)**2-4*(x**2+y**2+x*y-N)
            if b<0:continue
            for z in range(1,int(a+b**0.5)+1):
                if x**2+y**2+z**2+x*y+x*z+y*z==i:count+=1


    print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())
Ni=math.floor(math.sqrt(N))
for i in range(1,N+1):
	count=0
	for x in range(1,Ni):
		for y in range(x,Ni):
			for z in range(y,Ni):
				if x**2+y**2+z**2+x*y+y*z+z*x==i:
					if x==y==z:
						count+=1
					elif x==y or y==z:
						count+=3
					else:
						count+=6
	print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
for i in range(n):
    count = 0
    for x in range(1,int(math.sqrt(n))):
        for y in range(1,int(math.sqrt(n))):
            for z in range(1,int(math.sqrt(n))):
                if x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x == (i+1):
                    count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input()) + 1
Nroot = int(math.sqrt(N)) - 1
for n in range(1,N):
    count = 0
    if n >= 6:
#        print(Nroot, int(math.pow(n,1/3))-1)
        for x in range(Nroot, int(math.pow(n,1/3))-1 , -1):
            for y in range(x,0,-1):
                if (x+2*y)**2 < n:
                    break
                for z in range(1,y+1):
#                    print((x + y + z)**2 - (x*y + y*z + z*x), n,x,y,z)
#                    print(x,y,z)
                    formula = (x + y + z)**2 - (x*y + y*z + z*x)
                    if formula == n:
                        if x == y and y == z:
                            count += 1
                        else:
                            count += 3
                        break

        print(count)
    else:
        print("0")

Submission status: Time Limit Exceeded

Solution code:
def f(n):
  cnt = 0
  for i in range(int((n-3)**1/2 //1)):
    for j in range(int((n-3)**1/2 //1)):
      for k in range(int((n-3)**1/2 //1)):
        if (i+1)**2 + (j+1)**2 + (k+1)**2 + (i+1)*(j+1) + (j+1)*(k+1) + (k+1)*(i+1) == n:
          cnt += 1
  return cnt
    
N = int(input())
for i in range(N):
  print(f(i+1))

Submission status: Time Limit Exceeded

Solution code:
import math as m
N=int(input())
for n in range(1,N+1):
    if n>5:
        xmax=int(m.sqrt(n-5))
        ans=0
        for x in range(1,xmax+1):

            ymax=int((-(x+1)+m.sqrt(4*n-3*x**2-2*x-3))/2)
            if ymax>x:
                ymax=x 
            for y in range(1,ymax+1):
                D=4*n-3*(x**2+y**2)-2*x*y
                if D>=0 and m.sqrt(D)-(x+y)>1 and m.sqrt(D).is_integer():
                    z=int((-(x+y)+m.sqrt(D))/2)
                    if z<=y:
                        #if x**2+y**2+z**2+x*y+y*z+z*y==n:
                        #print('n=',n,[x,y,z])
                        if len(list(set([x,y,z])))==3:
                            ans+=6
                        elif len(list(set([x,y,z])))==2:
                            ans+=3
                        elif len(list(set([x,y,z])))==1:
                            ans+=1
    else:
        ans=0
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
x = 0
y =0 
z =0
for m in range(1,N+1):
  l = math.sqrt(m)
  li = int(l)
  count =0
  for i in range(li):
    x = i+1
    for k in range(x):
      y = k+1
      for j in range(y):
        z = j+1
        n = x*x+y*y+z*z+x*y+y*z+z*x
        if n==m:
          if  x==y or y==z or z==x:
            if x==y and y == z:
              count =count+1
            else:
              count = count+3
          else:
            count =count+6
  print(count)

Submission status: Time Limit Exceeded

Solution code:
s1 = input().split()
intN = int(s1[0])

i = 1
while i <= intN :
    cnt = 0
    wkX = 1
    while wkX <= i -5 :
        if (wkX * wkX > i -5) : 
            break
        wkY = 1
        while wkY <= i - 5 :
            if (wkY * wkY > i -5) : 
                break
            if (wkX * wkY > i -5) : 
               break
            wkZ = 1
            while wkZ <= i - 5 :
                if (wkZ * wkZ > i -5) : 
                   break
                if (wkY * wkZ > i -5) : 
                    break
                if (wkZ * wkX > i -5) : 
                    break
                intFn = wkX * wkX + wkY * wkY + wkZ * wkZ + wkX * wkY + wkY * wkZ + wkZ * wkX
                if (intFn == i) :
                    cnt += 1
                wkZ += 1
            wkY += 1
        wkX += 1
    print(cnt)
    i += 1

Submission status: Time Limit Exceeded

Solution code:
import math

N=int(input())
sqN = int(math.sqrt(N))+1

sq=list()
for i in range(1,200):
    sq.append(i*i)

def isSquare(n):
    if n in sq:
        return True
    else:
        return False

ans=list()
for i in range(1,min(N+1,6)):
    ans.append(0)

if N>5:
    for m in range(6,N+1):
        cnt = 0
        for x in range(1,sqN):
            for y in range(x,sqN):
                if x*x+y*y+x*y+x+y > m:
                    break

                b = x+y
                D = -3*(x*x+y*y)-2*x*y+4*m

                # print(m,x,y,D,isSquare(D))
                if D > 0 and isSquare(D):
                    sqD=sq.index(D)+1
                    if (sqD-b) > 0 and (sqD-b) % 2 == 0:
                        # z= (sqD-b)//2
                        # print(x,y,z)
                        # print(x*x+y*y+z*z+x*y+y*z-m)
                        if x != y:
                            cnt+=2
                        else:
                            cnt+=1
                if D < 0:
                    break
        ans.append(cnt)

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
for i in range(1,N+1):
  count = 0
  if i>5:
    for x in range(1,int((i-2)**0.5-1)+1):
      for y in range(1,int((i-2)**0.5-1)+1):
        z = (-(x+y)+((x+y)**2-4*(x**2+y**2+x*y-i))**0.5)
        if z == int(z.real) and z>0:
            count = count+1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
 
NUM_MAX = int(math.sqrt(n))+1
 
def my_func(k):
    ans = 0
    for x in range(1, NUM_MAX):
        for y in range(1, x+1):
            for z in range(1, y+1):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == k:
                    if (x==y==z):
                        ans += 1
                    elif x==y or y==z or z==x:
                        ans += 3
                    else:
                        ans += 6
    print(ans)
 
    
for i in range(1, n+1):
    my_func(i)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

n = int(input())


for i in range(1, n + 1):
    ans = 0
    OneToRootn = list(range(1, math.ceil(math.sqrt(i))))
    for xyz in list(itertools.combinations_with_replacement(OneToRootn, 3)):
        if (xyz[0] * xyz[0] + xyz[1] * xyz[1] + xyz[2] * xyz[2]+xyz[0]*xyz[1]+xyz[1]*xyz[2]+xyz[2]*xyz[0] == i):
            if (len(set(xyz)) == 1):  # 3つ同じ
                # print(xyz)
                ans += 1
            elif (len(set(xyz)) == 2):
                ans += 3
            else:
                ans += 6
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
for i in range(2, 2*N+1, 2):
    C = 0
    for x in range(2, i):
        if 3*x**2 > i:
            break
        for y in range(x, i):
            if x**2 + 2 * y**2 > i:
                break
            z_2 = i - x**2 - y**2
            z = int(math.sqrt(z_2))
            if z**2 == z_2:
                X_2, Y_2, Z_2 = x+y-z, x-y+z, -x+y+z
                if X_2 % 2 == 0 and Y_2 % 2 == 0 and Z_2 % 2 == 0:
                    if X_2 > 0 and Y_2 > 0 and Z_2 > 0:
                        if X_2 == Y_2 == Z_2:
                            C += 1
                        elif X_2 != Y_2 != Z_2:
                            C += 6
                        else:
                            C += 3
    print(C)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

n = int(input())

for num in range(1, n+1):
    count = 0
    prod = product(list(range(1, n)), repeat=3)
    for i in prod:
        x = i[0]
        y = i[1]
        z = i[2]

        if x**2 + y**2 + z**2 +x*y + y*z + z*x == num:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def f(n):
    a = 0
    b = 0
    c = 0
    d = 0
    ###
    x = 1
    while 6 * (x**2) < n:
        x += 1
    if 6 * (x**2) == n:
        a += 1
    x = 1
    while 6 * (x**2) < n:
        z = x+1
        while 3 * (x**2) + 2 * x * z + (z**2) < n:
            z += 1
        if 3 * (x**2) + 2 * x * z + (z**2) == n:
            b += 1
        x += 1
    x = 1
    while 6 * (x**2) < n:
        y = x+1
        while (x**2) + 2 * x * y + 3 * (y**2) < n:
            y += 1
        if (x**2) + 2 * x * y + 3 * (y**2) == n:
            c += 1
        x += 1
    x = 1
    while 6 * (x**2) < n:
        y = x+1
        while (x**2) + 3 * (y**2) + 2 * x * y < n:
            z = y+1
            while (x**2) + (y**2) + (z**2) + x * y + y * z + x * z < n:
                z += 1
            if (x**2) + (y**2) + (z**2) + x * y + y * z + x * z == n:
                d += 1
            y += 1
        x += 1
    return a + 3 * (b + c) + 6 * d

for i in range(n):
    print(f(i+1))

Submission status: Time Limit Exceeded

Solution code:
import math
N=int(input())

for i in range(1,N+1):
  n_max=math.ceil(math.sqrt(i))
  n_min=math.floor(math.sqrt(i/6))
  res=0

  for x in range(n_min,n_max+1):
    for y in range(1,x+1):
      for z in range(1,y+1):
        if x*x+y*y+z*z+x*y+y*z+z*x==i:
          if x==y and y==z:
            res+=1
          elif x==y or y==z:
            res+=3
          else:
            res+=6
  print(res)

Submission status: Time Limit Exceeded

Solution code:
def fib(x,y,z,m):
    ret=0
    if x**2+y**2+z**2+x*y+y*z+z*x==m:
      ret=1
    return ret

N=int(input())

for i in range(1,N+1):
    count=0
    m=i
    for x in range(1,m):
        for y in range(1,m):
            for z in range(1,m):
                if fib(x,y,z,m):
                    count=1+count
    print(str(count))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
for i in range(1,n+1):
  if(i < 6):
    print(0)
  else:
    count=0
    for x in range(1,i+1):
      for y in range(1,i+1):
        for z in range(1,i+1):
          num = x*x + y*y + z*z + x*y + x*z + y*z
          if num==i:
            count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
def main(n):
  ans=0
  
  for _ in range(1, n+1):
    if n>5:
      for i in range(1, int(_**0.5)):
        x=i
        for j in range(1, int(_**0.5)):
          y=j
          for h in range(1, int(_**0.5)):
            z=h
            if x**2+y**2+z**2+x*y+y*z+x*z==_:
              ans += 1
    print(ans)
    ans=0
    
n=int(input())
main(n)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def f(n):
    flag = False
    #total = 0
    ans = 0
    i = 134
    for x in range(1,i):
        for y in range(1,i-x):
            for z in range(1,i-(x+y)):
                if (x + y + z)**2 - (x*y + y*z + x*z) == n:
                    #total += 1
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    if x == i-1:
        ans = 0
    elif x == y and  y== z:
        ans = 1
    elif x == y or y == z or x == z:
        ans = 3
    else:
        ans = 6
    return ans

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

def func(n):
    cnt = 0
    for x in range(1, 20):
        if x * x > n:
            break
        for y in range(1, 20):
            if y * y > n:
                break
            for z in range(1, 20):
                if z * z > n:
                    break
                if x * x + y * y + z * z + x * y + y * z + z * x == n:
                    cnt += 1
                    break
    return cnt


def main():
    N = int(input())

    for i in range(1, N + 1):
        print(func(i))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations_with_replacement

n = int(input())

for i in range(1, n+1):
    ans = 0
    for v in combinations_with_replacement(range(1, 40), 3):        
        x, y, z = v

        if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
            if x == y == z:
                ans = 1
            else:
                ans = 3
            break

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

@lru_cache(maxsize=None)
def calc_xyz(ix,iy,iz,n):
    if ix ** 2 + iy **2 + iz ** 2 + ix * iy + iy* iz + iz * ix == n:
        return(1)
    else:
        return(0)


def calc_func(n):
    result = 0
    for ix in range(1,n+1):
        for iy in range(1,n+1):
            for iz in range(1,n+1):
                # if ( ix  + iy  + iz ) ** 2 >= n:
                #     continue
                # if ix ** 2 + iy **2 + iz ** 2 + ix * iy + iy* iz + iz * ix == n:
                #     result += 1
                Atmp = [ix, iy, iz]
                A = sorted(Atmp)
                result += calc_xyz(*A, n)
    return(result)


N = int(input()) #1行目のNを取得する


for i in range(N):
    print(calc_func(i+1))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

for i in range(1, N+1):
    count = 0
    for x in range (1, i):
        for y in range(1, i):
            for z in range(1, i):
                if int(x**2) + int(y**2) + int(z**2) +int(x*y) + int(y*z) + int(z*x) == i:
                    count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def count_n(n):
    ans = 0
    for x in range(1,int(N**0.5)+1):
        if 6*x**2 == n:
            ans = 1
            return ans
        else:
            for y in range(1,int(N**0.5)+1):
                    if (3*x**2 + y**2 + 2*x*y)  == n:
                        ans += 3
                        return ans
    return ans

for i in range(1,N+1):
    print(count_n(i))

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())

def search(n):
    global N
    for x in range(1, int(math.sqrt(N)) + 1):
        if n - x*x <= 0:
            return None
        for y in range(1, int(math.sqrt(N)) + 1):
            if n - x*x - y*y - x*y <= 0:
                break
            z = binarySearch(n, x, y)
            if z:
                return (x, y, z)


def binarySearch(n, x, y):
    global N
    right = -1
    left = N + 1
    while(abs(right - left) > 1):
        z = left + (right - left) // 2
        l = x*x + y*y + z*z + x*y + y*z + z*x
        if l == n:
            return z
        elif l < n:
            right = z
        else:
            left = z
        # print(right, left, z)
    return None

for n in range(1, N+1):
    ans = search(n)
    if ans == None:
        print(0)
        continue
    ans = len(set(ans))
    if ans == 1:
        print(1)
    elif ans == 2:
        print(3)
    else:
        print(6)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import statistics
import itertools
from collections import deque
n=int(input())
#n,m=map(int,input().split()))
#lis=list(map(int,input().split()))
#side=[]
#for _ in range(m):
    #side.append(tuple(map(int,input().split())))
ans_lis =[0]*1000000

#per_lis=itertools.permutations(list(range(1,4)))


def f(a):
    A=int(math.sqrt(a))
    cnt=0
    for i in range(1,A+1):
        for j in range(1,A+1):
            for k in range(1,A+1):
                tmp=i**2+j**2+k**2+i*j+j*k+k*i
                if tmp==a:
                    cnt+=1
    return cnt
for i in range(1,n+1):
    print(f(i))

Submission status: Time Limit Exceeded

Solution code:
def f(num):
    ans=0
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                if x==y==z and x**2+y**2+z**2+x*y+y*z+z*x==num:
                    ans+=1
                    return ans
                elif x**2+y**2+z**2+x*y+y*z+z*x==num:
                    ans+=3
                    return ans
    return ans

N=int(input())
for i in range(N):
    print(f(i+1))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())

def func(N):
    count = 0
    for x in range(1, 101):
      for y in range(1, 101):
          D = (x+y)**2 -4*(x**2 + y**2+ x*y - N)
          if D > 0:
              z = -(x+y)/2 + np.sqrt(D) / 2
              if z.is_integer() and z >= 1:
                  count += 1
    return count
  
  
for n in range(1,N+1):
  print(func(n))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=[0]*(n+1)
def triplets(n):
    ans=0
    for x in range(1,n//3):
        for y in range(1,n//3):
            for z in range(1,n//3):
                if x**2 + y**2 + z**2 + x*y + y*z + x*z == i:
                    ans+=1
    return ans
for i in range(1,n+1):
    ans[i]=triplets(i)
ans=ans[1::]
print(*ans, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
import numpy as np
#max=int(np.sqrt(N))
for n in range(1,N+1):
    j=0
    max = int(np.sqrt(abs(n-2)))
    #print(max)
    for x in range(1,max):
        for y in range(1, max):
            for z in range(1, max):
                if x**2+y**2+z**2+x*y+y*z+z*x==n:
                    #print(x, y, z)
                    #print(f'n:{n}')
                    j+=1
    print(j)