求圆上和谐点数

来源:互联网 发布:linux 建网站 编辑:程序博客网 时间:2024/04/30 11:26

问题描述:

假设一个圆是X**2+Y**2=N,定义在圆上的整数坐标的点为和谐点,例如

N为25时,(±3,±4),(±4,±3), (±5,0), (0,±5) 这12个点为和谐点。


解法:(Python3)

import sysimport mathdef find_pointnum(n):    count = 0    n=float(n)    l = int(math.sqrt(n))    for i in range(l+1):          for j in range(i,l+1):  #对1/8象限内做遍历            if i**2+j**2 == n:                if i==0 or j==0 or i==j:                    count+=1  #边界加1                else:                    count+=2  #中心加2    return count*4  #四个象限  if __name__ == '__main__':    n = sys.stdin.readline().strip()    print (find_pointnum(n))



0 0
原创粉丝点击