python-3.x - 我正在尝试编写与拉格朗日四平方定理相关的东西,我该如何优化我的代码,因为它不能按时通过所有测试
问题描述
任务是:给定一个正整数 n,在 a² + b² + c² + d² = n 和 b + 3c + 5d = 的非负整数上找到有序元组 (a, b, c, d, e) 的数量e²。
n = int(input())
count = 0
for e in range(3 * math.floor(math.sqrt(math.sqrt(n))) + 2):
for c in range(math.floor(math.sqrt(n)) + 1):
for b in range(math.floor(math.sqrt(n)) + 1):
if (e**2-b-3*c)/5 == int((e**2-b-3*c)/5) and (e**2-b-3*c) >= 0:
for a in range(math.floor(math.sqrt(n)) + 1):
if a**2 +(26*b**2+6*b*c-2*e**2*b+34*c**2-6*e**2*c+e**4)/25 == n:
count += 1
print(count)
解决方案
推荐阅读
- vb.net - 使用 BackgroundWorker 通过 FileSystemWatcher 更新主窗体 UI?
- javascript - 如何在JS中获取数组中的每个备用对象
- join - PowerBI - 在 DAX 中加入 DirectQuery 和导入的表
- android - Kivy 期间没有名为 google 的模块到使用 Buildozer 进行 apk
- javascript - 如何使用 kendo ui 将 excel 文件上传到服务器
- c# - 调试模式下的变量检查器不显示 Guid 和 DateTime 的值 - Visual Studio 2019 (Xamarin Forms)
- yaml - 以自定义变量为条件的 Azure 管道
- wordpress - 使用 REST API 创建带有外部附件 URL 的产品
- security - 为什么 AWS Cognito 访问令牌的生命周期是 1 小时,是不是太长了?为什么aws不允许通过控制台或sdk设置它?
- list - 将项目添加到现有列表 mvc5