鱼C论坛

 找回密码
 立即注册
查看: 5823|回复: 13

题目39:如果p是直角三角形{a,b,c}的周长,1000以下的p中哪一个具有最多的解?

[复制链接]
发表于 2019-6-14 12:22:17 | 显示全部楼层
最多解为:8
用时:7.80005 秒

  1. import time


  2. def cal_result():
  3.     result = []
  4.     for p in range(12, 1000):
  5.         count = 0
  6.         for x in range(int(p//3), p):
  7.             for y in range(x-1, 0, -1):
  8.                 if x + y >= p:
  9.                     break
  10.                 else:
  11.                     z = p - x - y
  12.                     if z <= y:
  13.                         if x**2 == y**2 + z**2:
  14.                             count += 1
  15.                     else:
  16.                         break
  17.         if count != 0:
  18.             result.append((p, count))
  19.     return result

  20. result = cal_result()
  21. max_result = max(each[1] for each in result)
  22. print("最多解为:{}\n用时:{} 秒".format(max_result, time.process_time()))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-9 04:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表