【Number Theory】Pythagorean Triples Generating Program
来源:互联网 发布:开网络棋牌 编辑:程序博客网 时间:2024/06/05 19:42
# this program is for generating the Pythagorean Triples(a, b, c).# using the Pythagorean Triples Theorem:# a = s*t, b = (s**2 - t**2)/2, c = (s**2 + t**2)/2.# s and t are odd, and they are relatively prime. sortByA = open("PythagoreanTriplesSortByA.txt", "w")sortByB = open("PythagoreanTriplesSortByB.txt", "w")sortByC = open("PythagoreanTriplesSortByC.txt", "w")T = int(input("input the max t(odd) for iterator:"))S = int(input("input the max s(odd and normally bigger than T) for iterator:"))pythagoreanTriplesList = []for t in range(1, T + 1, 2): for s in range(t + 2, S + 1, 2): triple = (s * t, int((s**2 - t**2)/2), int((s**2 + t**2)/2)) pythagoreanTriplesList.append(triple)# sorted by apythagoreanTriplesList.sort(key = lambda triple : triple[0])for i in range(0, len(pythagoreanTriplesList)): triple = pythagoreanTriplesList[i] sortByA.write("({0}, {1}, {2})\n".format(triple[0], triple[1], triple[2])) # sorted by bpythagoreanTriplesList.sort(key = lambda triple : triple[1])for i in range(0, len(pythagoreanTriplesList)): triple = pythagoreanTriplesList[i] sortByB.write("({0}, {1}, {2})\n".format(triple[0], triple[1], triple[2])) # sorted by cpythagoreanTriplesList.sort(key = lambda triple : triple[2])for i in range(0, len(pythagoreanTriplesList)): triple = pythagoreanTriplesList[i] sortByC.write("({0}, {1}, {2})\n".format(triple[0], triple[1], triple[2]))
1 0
- 【Number Theory】Pythagorean Triples Generating Program
- Pythagorean Triples
- [codeforces707C]Pythagorean Triples
- Codeforce707 C. Pythagorean Triples
- C. Pythagorean Triples
- C. Pythagorean Triples
- codeforces 707C - Pythagorean Triples
- codeforces 707C Pythagorean Triples
- 【codeforces 707C Pythagorean Triples】
- #368 C. Pythagorean Triples 勾股数
- codeforces--707C. Pythagorean Triples
- CodeForces 707C-Pythagorean Triples
- [codeforces] C - Pythagorean Triples 数学
- 勾股数列表(Find Pythagorean Triples)
- Codeforces Round #368-C - Pythagorean Triples-数学
- Codeforces Round #368 (Div. 2) Pythagorean Triples
- Codeforces Round #368 C Pythagorean Triples
- codeforces 707 C Pythagorean Triples【数学】
- Vertia的这些事<一>—— 关于vertica的常用操作
- [Leetcode]Scramble String
- Android应用--首次使用的欢迎界面,之后不再显示
- java mybatis:Result Maps collection does not contain value for java.lang.Long
- [js编程题]添加元素 slice splice
- 【Number Theory】Pythagorean Triples Generating Program
- 事务的概念及事务的四个特征
- 【项目管理】之springMVC+spring+Mybatis环境搭建
- 设置MyEclipse或Eclipse 中 Jsp页面的默认编码
- Android Handler内存泄露分析
- cocos ide 调试lua 程序自动关闭问题的解决
- 使用retn指令调用API
- django 在应用app下面template
- tomcat启动,报问题:To prevent a memory leak, the JDBC Driver has been forcibly unregistered.