Leetcode 1925. Count Square Sum Triples

Problem

A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2.

Given an integer n, return the number of square triples such that 1 <= a, b, c <= n.

Algorithm

Count the number of Pythagorean triples by enumerating them according to the definition.

Code

python3 复制代码
class Solution:
    def countTriples(self, n: int) -> int:
        cnts = 0
        for a in range(2, n):
            for b in range(2, n):
                c_2 = a * a + b *b
                c = int(sqrt(c_2))
                if c <= n and c * c == c_2:
                    cnts += 1
        return cnts
相关推荐
Beyond_System|系统之外13 分钟前
【学编程】Python基础编程题100道(21-60)
开发语言·python·算法
漂流瓶jz2 小时前
UVA-1442 洞穴 题解答案代码 算法竞赛入门经典第二版
c++·算法·题解·aoapc·算法竞赛入门经典·uva
圣保罗的大教堂2 小时前
leetcode 835. 图像重叠 中等
leetcode
叠层归一研究院3 小时前
基于极限自指的叠层归一宇宙结构理论——无元外部封闭系统的内生区分模型
人工智能·经验分享·算法·agi
Selvaggia4 小时前
Diffusion Model 的基本原理与模型架构
算法
wabs6666 小时前
关于二叉树【力扣572.另一棵树的子树的思考】
数据结构·c++·算法·leetcode·二叉树
hanlin036 小时前
刷题笔记:力扣第41题-缺失的第一个正数
笔记·算法·leetcode
shehuiyuelaiyuehao6 小时前
算法50,分治归并,数组中的逆序对
java·算法
阳明山水7 小时前
校准分位数驱动智能库存决策
人工智能·深度学习·算法·机器学习·架构
别动我齐刘海8 小时前
ROS2 Jazzy + C++ 实战路线——进阶学习3
c++·人工智能·vscode·python·算法·机器学习·机器人