FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/ProjectEuler/Problem09.java at master · debugmm/Java · GitHub
debugmm
/
Java
Public
forked from
TheAlgorithms/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
ProjectEuler
/
Problem09.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (26 loc) · 721 Bytes
Breadcrumbs
Java
/
ProjectEuler
/
Problem09.java
Copy path
File metadata and controls
28 lines (26 loc) · 721 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 */
}
}
Back
|
FazBrowse Home
|
New Git URL