-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay 17.1.txt
45 lines (32 loc) · 898 Bytes
/
Day 17.1.txt
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
1925. Count Square Sum Triples
A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2.
Given an integer n, return the number of square triples such that 1 <= a, b, c <= n.
Example 1:
Input: n = 5
Output: 2
Explanation: The square triples are (3,4,5) and (4,3,5).
Example 2:
Input: n = 10
Output: 4
Explanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10).
Constraints:
1 <= n <= 250
class Solution {
public int countTriples(int n) {
if(n<5)
return 0;
double k;
int c=0,i,j;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
k=(i*i)+(j*j);
k=(int)Math.sqrt(k);
if(k==Math.sqrt((i*i)+(j*j))&&k<=n)
c+=2;
}
}
return c;
}
}