"""
ID: ***
LANG: PYTHON3
TASK: ariprog
"""
import math
import time
start_time = time.time()
fin = open ('ariprog.in', 'r')
fout = open ('ariprog.out', 'w')
N = int(fin.readline())
M = int(fin.readline())
num_max = 2*math.pow(M,2)
record_List = list()
num_List = list()
gd = False
for x in range(M+1):
for y in range(M+1):
num_List.append(int(math.pow(x,2)+math.pow(y,2)))
num_List = list(set(num_List))
num_List.sort()
print("time1: {}".format(time.time()-start_time))
def checkNum(sPt, num_List,b)->bool:
for j in range(2,N):
if(int(num_List[sPt]+b*j) not in num_List):
return False
return True
for i in range(0, len(num_List)-N+1):#STARTING P
for j in range(i+1, len(num_List)-N+2):
b = num_List[j]-num_List[i]
if num_List[i]+(N-1)*b > num_max:
break
if checkNum(i,num_List,b):
record_List.append([num_List[i],b])
record_List = sorted(record_List,key=lambda x: x[1 ])
print("time2: {}".format(time.time()-start_time))
if len(record_List)==0 :
fout.write("NONE\n")
else:
for x in record_List:
fout.write("{} {}\n".format(x[0],x[1]))
fout.close()
USACO Python3 1.5 Arithmetic Progression
最新推荐文章于 2025-01-30 23:05:35 发布