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: Wrong Answer

Solution code:
import math

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

    end = N

    for i in range(3,end+1):
        sn = i
        x = 1
        y = 1
        z = sn - 2
        if(cal(x,y,z) < N):
            ans[cal(x,y,z)] += func(x,y,z)
        while True:
            y += 1
            z -= 1
            if x > z or y > z:
                break
            if(cal(x,y,z) < N):
                ans[cal(x,y,z)] += func(x,y,z)
            for j in range(y - 1):
                x += 1
                z -= 1
                if x > z or y > z:
                    break
                if(cal(x,y,z) < N):
                    ans[cal(x,y,z)] += func(x,y,z)
    
    for i in range(1,N+1):
        print(ans[i])
        

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

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

main()

Submission status: Wrong Answer

Solution code:
import math


def keisan(N):
    ans = 0
    #j = int(math.sqrt(N/6))
    
    j= 48
    
    for x in range(1,j+1):
        for z in range(1,j+1):
            D =  (x+z)*(x+z)-4*(x*x+z*z+z*x-N)
            if D>=0:
                y = -(x+z)+math.sqrt(D)
                y = y/2
                #print(y)
                #print(y.is_integer())
                if y>=1 and y.is_integer() == True:
                    ans = ans+1
                    #print(x,y,z)
    print(ans)
        

N = int(input())
for i in range(1,N+1):
    keisan(i)

Submission status: Wrong Answer

Solution code:
N = int(input())

for n in range(1, N+1):
    s = n//5
    cnt = 0
    flag = 0
    f2 = 0
    for x in range(1, s+1):
        for y in range(x, s+1):
            for z in range(y, s+1):
                siki = x**2 + y**2 + z**2 + x*y + y*z + z*x

                if siki == n:
                    # print('ans = ', siki)
                    if (x==y)and(y==z):
                        cnt += 1
                    elif (x!=y)and(y!=z):
                        cnt += 6
                    else:
                        cnt += 3
                # elif siki > n:
                    flag = 1
                    break
                elif siki > n:
                    f2 += 1
                    # print('fs= ', f2)
                    # print('x,y,z= ',x,y,z)
                    break

            if flag or f2>=2:
                break
        if flag or f2==2:
            break
    print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import math

def main():
    input = sys.stdin.readline
    N = int(input())

    result = 0
    ok_flag = False
    for n in range(N+1):
        root_n = int(math.sqrt(n)) + 1
        if n < 3:
            print(0)
            continue
        for i in range(1,root_n):
            for j in range(1,root_n):
                for k in range(i,root_n):
                    if i*i + j*j + k*k + i*j + i*k + j*k == n:
                        if i == j and j == k:
                            result += 1
                        elif i == j or j == k or i == k:
                            result += 3
                        else:
                            result += 6
                        print(result)
                        result = 0
                        ok_flag = True
                        break
                if ok_flag:
                    break
            if ok_flag:
                break
            
        if not ok_flag:
            print(0)
        ok_flag = False

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
ans_d = {i: 0 for i in range(1,10001)}

p = itertools.product(range(1, 100), range(1, 100), range(1, 100))

for x, y, z in p:
    cnt = (x ** 2) + (y ** 2) + (z ** 2) + (x * y) + (y * z) + (x * z)
    if cnt <= 10000:
        ans_d[cnt] += 1

for i, j in ans_d.items():
    print(i,j)
    if i == n:
        break

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import maxsize


def two_div(l):
    divs = []
    if l == 2:
        return [(1,1)]
    if l == 3:
        return [(2,1)]
    preL = 0
    for m in range(l-1,l//2 -1,-1):
        if preL == l-m:
            break
        divs.append((m,l-m))
        preL = m
    return divs


def three_div(mmm):
    if mmm == 3:
        return[(1,1,1)]
    if mmm == 4:
        return[(2,1,1)]
    divs = []
    rest = 1
    for m in range(mmm-2,mmm//3 -1,-1):
        rest += 1
        two_c = two_div(rest)
        for t in two_c:
            if m < t[0]:
                continue
            c = (m,t[0],t[1])
            divs.append(c)
    return divs

def triple(x,y,z):
    v = x*x + y*y + z*z + x*y + y*z + z*x
    return v

def main():
    n = int(input())
    ans = [0] * (n+1)
    for goukei in range(3,100):
        mini = maxsize
        factors = three_div(goukei)
        # print("================")
        for x,y,z in factors:
            # print(x,y,z)
            v = triple(x,y,z)

            if x == y and y == z and v <= n:
                ans[v] += 1
            elif v <= n:
                ans[v] += 3

            if mini > v:
                mini = v
        if mini >= n:
            break

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
z=0
d=0
ans=0
for i in range(1,n+1):
  for x in range(1,int(math.sqrt(n)+1)):
    d=4*x*x-4*(3*x*x-i)
    if d<0:
      continue
    z=(math.sqrt(d)-2*x)/2
    if z.is_integer():
      if x==int(z) and int(z)>=1:
        ans+=1
        continue
      elif int(z)>=1:
        ans+=3
        continue
    else:
      continue
  print(ans)
  ans=0

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
for i in range(n):
    cnt = 0
    for x in range(1,n):
        for y in range(1,n):
            b = x + y
            c = x**2+y**2+x*y-i
            buf = b**2-4*c
            if buf >= 0:
                z = -b + math.sqrt(buf)
                if z.is_integer() and z > 0:
                    cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
# 幅優先探索（行きがけ）
import collections
import sys
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    if N <= 5:
        for i in range(N):
            print(0)
        return

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

    for i in range(5):
        print(0)

    for i in range(6, N+1):
        cn = 0
        n = math.floor(math.sqrt(i)+1)
        start = math.floor(math.sqrt(i/6)-1)
        for j in range(start, n):
            if j**2 >= i-4:
                break
            for k in range(start, j+1):
                if j**2+k**2+j*k >= i-2:
                    break
                for l in range(start, k+1):
                    y = yy(j, k, l)
                    if y > i:
                        break
                    if y == i:
                        if j == k == l:
                            cn += 1
                        elif j != k != l:
                            cn += 6
                        else:
                            cn += 3
        print(cn)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(1, n + 1):
  cnt = 0
  for x in range(1, 65):
    for y in range(x, 65):
      for z in range(y, 65):
        if (x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2 == i * 2:
          if x != y and y != z and z != x:
            cnt += 6
          elif x == y == z:
            cnt += 1
          else:
            cnt += 3
  ans.append(cnt)
for j in range(n):
  print(ans[j])

Submission status: Wrong Answer

Solution code:
import math
N = int(input()) + 1
#Nroot = int(math.sqrt(N/3))+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(int(math.sqrt(n/3))+1, int(math.sqrt(n/3))-1 , -1):
            for y in range(x,0,-1):
                if (x+2*y)**2 - (2*x + y) * y >= n:
                    for z in range(y,0,-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
                        elif formula < n:
                            break


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

Submission status: Wrong Answer

Solution code:
N=int(input())
la=list(range(2,10**2+1))
l=[]
for i in range(len(la)):
  l.append(la[i]**2)
for n in range(1,N+1):
  if n<6:
    print(0)
  else:
    c=0
    for x in range(len(l)):
      if l[x]*3>2*n:
        break
      else:
        for y in range(x,len(l)):
          if l[x]+2*l[y]>2*n:
            break
          else:
            for z in range(y,min(x+y+2,len(l))):
              if l[x]+l[y]+l[z]>2*n:
                break
              else:
                
                if l[x]+l[y]+l[z]==2*n:
                  
                  if (x+y+z)%2==0: 
                      if l[x]==l[y] and l[y]==l[z]:
                        c+=1
                      elif l[x]==l[y] or l[y]==l[z]:
                        c+=3
                      else:
                        c+=6
                   
    print(c)

Submission status: Wrong Answer

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


x = 1
y = 1
z = 1

ans = 6
first_judge = 1
ans_out = 0
#print("ans 6")

if N <= 5:
    for i in range(N):
        print(l[i])
else:
    while ans <= N:
        # print("x,y,z=",x,y,z)
        ans = (x + y + z)**2 - (x*y+ y*z + z*x)
        # print("ans",ans)
        if first_judge == 1 and ans > N:
            if ans_out >= 2:
                # print("break!")
                break
            else:
                x += 1
                y = x
                z = x
                ans_out += 1
                first_judge = 1
                ans = 0
                # print("x_++ x,y,z=",x,y,z)
                # print("first_judge=1")
                # print("ans_out=",ans_out)
        elif ans <= N:
            ans_out = 0
            if x==y==z:
                # print("x=y=z!")
                # print("first_judge=0")
                l[ans-1] += 1
                first_judge = 0
            else:
                # print("list in")
                # print("first_judge=0")
                l[ans-1] += 3
                first_judge = 0
            z += 1
        else:
            y += 1
            z = y
            first_judge = 1
            ans_out += 1
            ans = 0
            # print("kousin x,y,z=",x,y,z)
            # print("first_judge=1")
            # print("ans_out=",ans_out)
            
        # print("\n")
        
    for i in range(N):
        print(l[i])

Submission status: Wrong Answer

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
n = int(input())
arr = list()
e = list()
ans = []
temp1 = 0
for i in range(1,n+1):
	temp2 = 0
	for j in range(1,n+1):
		temp3 = 0
		for k in range(1,n+1):
			if i == j == k: kk = 1
			if i!=j and j!= k: kk = 6
			if i==j or j== k: kk = 3
			e.append(kk)
			arr.append(i*i + j*j + k*k + i*j + j*k + k*i)
			temp3 = i*i + j*j + k*k + i*j + j*k + k*i
			#print(temp3, i+j+k)
			if temp3 > n:break
		temp2 = i*i + j*j + 1 + i*j + j + i
		if temp2 > n: break
	temp1 = i*i + 1 + 1 + i + 1 + i
	if temp1 > n:
		break
	


#print(arr)
#print(e)
for i in range(1,n+1):
	f = 1
	for j in range(len(arr)):
		if arr[j] == i:
			ans.append(e[j])
			f = 0
			break
	if f: ans.append(0)
for i in ans:
	print(i)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())
#L, R, d=map(int,input().split())
#C = []
# for i in range(N):
#    C.append((input().replace(".","0").replace("#","1")))
# S=list(map(int,input().split()))
# B=list(map(int,input().split()))
def calc1(x,y,z):
    return x*x+y*y+z*z+x*y+y*z+z*x
def calc2(x,y):
    return x*x+y*y+1*1+x*y+y*1+1*x
def calc3(x):
    return x*x+1*1+1*1+x*1+1*1+1*x

count = []
for n in range(1,N+1):
    count2 = 0
    l = []
    for i in range(1,int(n/2)):
        for j in range(i,int(n/2)):
            for k in range(j,int(n/2)):
                h = calc1(i,j,k)
                o = [i,j,k].sort
                if h > n:
                    break
                elif o in l:
                    count2+=1
                elif h == n:
                    count2+=1
                    l.append(o)
    count.append(count2)

print('\n'.join(map(str, count)))