zoukankan      html  css  js  c++  java
  • Project Euler Problem9

    Special Pythagorean triplet

    Problem 9

    A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

    a2 + b2 = c2

    For example, 32 + 42 = 9 + 16 = 25 = 52.

    There exists exactly one Pythagorean triplet for which a + b + c = 1000.
    Find the product abc.

     
    The code is simple:
    a = 0
    b = 0
    c = 0
    totalSum = 1000
    cMax = int(totalSum/2)
    cMin = int(totalSum/3)
    aMax = cMin
    c = cMax
    while c > cMin:
        b = c - 1
        while b > 1:
            a = totalSum - c - b
            if a > b or a < 1 or a > aMax:
                break
            if a*a + b*b == c*c:
                print(a, b, c)
                print(a*b*c)
                break
            b -= 1
        c -= 1
    

      

  • 相关阅读:
    基本HAL库操作函数整理
    oled(iic协议)
    Uart串口中断收发
    博主回来啦
    博主的冒泡1
    AFO

    起床困难综合症
    费解的开关
    数独
  • 原文地址:https://www.cnblogs.com/tianxiaozz/p/3471893.html
Copyright © 2011-2022 走看看