# Project Euler Problem 75 原

BlackJoker

It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.

12 cm: (3,4,5)
24 cm: (6,8,10)
30 cm: (5,12,13)
36 cm: (9,12,15)
40 cm: (8,15,17)
48 cm: (12,16,20)

In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.

120 cm: (30,40,50), (20,48,52), (24,45,51)

Given that L is the length of the wire, for how many values of L  1,500,000 can exactly one integer sided right angle triangle be formed?

Note: This problem has been changed recently, please check that you are using the right parameters.

``````public static void main(String[] args) {
Map<Integer, ABC> dict = new HashMap<Integer, ABC>();
int L = 1500000;
int M =  (int)Math.sqrt(L / 2);
for (int m = 1; m <= M; m++) {
for (int n = 1; n < m; n++) {
int a = m * m - n * n;
int b = 2 * m * n;
int c = m * m + n * n;
int l = a + b + c;
int k = L / l;
for (int i = 1; i <= k; i++) {
int[] abc = { i * a, i * b, i * c };
Arrays.sort(abc);
check(i, l, abc, dict);
}
}
}
int count = 0;
for (ABC abc : dict.values()) {
count += abc.got;
}
System.out.println(count);
}

private static void check(int i, int l, int[] abc, Map<Integer, ABC> dict) {
int ll = i * l;
ABC tmp = dict.get(ll);
if (tmp != null) {
if (tmp.got == 1) {
int[] tmp1 = tmp.abc;
for (int x = 0; x < 3; x++) {
if (tmp1[x] != abc[x]) {
tmp.got = 0;
break;
}
}
}
} else {
dict.put(ll, new ABC(abc));
}
}

static class ABC {
public ABC(int[] abc) {
this.abc = abc;
}

int got = 1;
int[] abc;

}``````

1，通过a = m^2 − n^2, b = 2mn, c = m^2 + n^2 （1）可以生成所有的素勾股数和一部分派生勾股数（a,b,c）,其在（m>n,m,n为正整数）;
2,勾股数分为素勾股数和派生勾股数，而且所有派生勾股数都是由素勾股数派生而来的;
3,根据1,2,利用式（1），遍历m，n并加上派生规则可以生成所有勾股数。

### BlackJoker

Pope怯懦懦地
2017/12/09
0
0
Euler Project Problem 6

The sum of the squares of the first ten natural numbers is, 1 2 + 2 2 + ... + 10 2 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10) 2 = 55 2 =......

2012/10/16
52
0
2018 Multi-University Training Contest 3

1001：Problem A. Ascending Rating 首先可以通过单调栈维护出每个位置右边第一个大于自己的数所在的位置，记为rightmax[i]，然后维护一个双端队列。双端队列里维护[L,L+m-1]中的最长上升子序...

Hetui
07/31
0
0

Pope怯懦懦地
2017/12/09
0
0
[Data Structures and Algorithms - 1] Introduction & Mathematics

References: 1. Stanford University CS97SI by Jaehyun Park 2. Introduction to Algorithms 3. Kuangbin's ACM Template 4. Data Structures by Dayou Liu 5. Euler's Totient Function Ge......

rgvb178
01/26
0
0

linux脚本中父shell与子shell 执行的几种方式

12分钟前
1
0
git简单操作

1、 git init 初始化仓库 git add 1.txt 添加文件 git commit -m ”commit” 提交更新，添加注释 git status 查看仓库状态 git log 查看日志 //修改文件后提交更新 git diff 查看有哪些修改 ...

xiaobai1315
17分钟前
1
0

19分钟前
1
0

20分钟前
1
0

HTTP协议： 引用：http://www.cnblogs.com/ranyonsue/p/5984001.html HTTP简介 HTTP协议是Hyper Text Transfer Protocol（超文本传输协议）的缩写,是用于从万维网（ WWW:World Wide Web）服务...

xiaoyaoyoufang
23分钟前
1
0