毕达哥拉斯三元运动 [英] pythagorean triples exercise

查看:160
本文介绍了毕达哥拉斯三元运动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要就以下练习的问题快速提示:

i need a quick hint regarding the following exercise question:

编写一个程序,生成所有毕达哥拉斯三元组的小边不大于n。其中n&LT试试吧。= 200

Write a program that generates all Pythagorean triples whose small sides are no larger than n. Try it with n <= 200.

什么是不超过N所有关于??

what is "no longer than n" all about ??

演习来源:Java的由夹层(艾拉·波尔和查理·麦克道尔)

exercise source: Java by Dissection (Ira Pohl and Charlie McDowell)

注:我发现了什么看起来是一个很好的后的毕达哥拉斯三元的,但我会看不懂现在还因为它可能会破坏我试图解决这个自己......

note: i found what looks to be a very good post on pythagorean triples but i won't read it yet as it might spoil my attempt to solve this myself....

修改

如果n是小侧的长度和我们说:n为5; 然后我需要检查所有的三元组,其中a = 1,= 2,= 3,= 4,= 5 并发现是毕达哥拉斯三元组的情况下,

if n is length of the small side a and we say: n is 5; then i need to check all triples with a=1,a=2,a=3,a=4,a=5 and find the cases that are Pythagorean triples

这是什么额外条件好?

编辑2

也许我会得到更接近,如果我告诉你一个实际的一块......所以这里是一段简短的(蟒蛇)code,返回几三倍。我已经设置为外循环,以20的上限(目前我看不到任何其他用途N),以保持它的可管理的职务。

maybe i'll get closer if i show you a practical piece...so here is a short piece of (python) code that returns a few triples. I've set the upper limit for the outer loop to 20 (for now i can't see any other use for 'n') to keep it managable for the post.

import math
for b in range(20):
    for a in range(1, b):
        c = math.sqrt( a * a + b * b)
        if c % 1 == 0:
            print (a, b, int(c))

这将返回

(3,4,5) (6,8,10) (5,12,13) (9,12,15) (8,15,17) (12,16,20)

(3, 4, 5) (6, 8, 10) (5, 12, 13) (9, 12, 15) (8, 15, 17) (12, 16, 20)

时,所期望的输出?那是什么我失踪了一步呢?

is that the desired output? what is the step that i'm missing?

在此先感谢

巴巴

推荐答案

毕达哥拉斯三元组是一个直角三角形的整数边。三角形的小侧面是形成直角的侧面(意味着不斜边)。

Pythagorean triples are the integer sides of a right triangle. The small sides of the triangle are the sides that form the right angle (meaning not the hypotenuse).

不小于n 意味着你将得到一个整数 N ,且必须生成一个整数的所有可能的三元组<$较大C $ C>农行,使得 A&LT; = N,B&LT; = N A ^ 2 + B ^ 2 = C ^ 2

no larger than n means you are given an integer n and must generate all possible triples of integers a b c such that a <= n, b <= n and a^2 + b^2 = c^2.

这篇关于毕达哥拉斯三元运动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆