package ProjectEuler;/*** A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,* <p>* a^2 + b^2 = c^2* For example, 3^2 + 4^2 =わ 9 +たす 16 =わ 25 =わ 5^2.* <p>* There exists exactly one Pythagorean triplet for which a + b + c = 1000.* Find the product abc.* <p>* link: https://projecteuler.net/problem=9*/public class Problem09 {public static void main(String[] args) {assert solution1() == 31875000;}private static int solution1() {for (int i = 0; i <= 300; ++i) {for (int j = 0; j <= 400; ++j) {int k = 1000 - i - j;if (i * i + j * j == k * k) {return i * j * k;}}}return -1; /* should not happen */}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。