C. Count Triangles
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputLike any unknown mathematician, Yuri has favourite numbers:
holds?
Yuri is preparing problems for a new contest now, so he is very busy. That's why he asked you to calculate the number of triangles with described property.
The triangle is called non-degenerate if and only if its vertices are not collinear.
Input
The first line contains four integers:
) — Yuri's favourite numbers.
Output
Print the number of non-degenerate triangles with integer sides
holds.
Examples
Input
Copy
1 2 3 4
Output
Copy
4
Input
Copy
1 2 2 5
Output
Copy
3
Input
Copy
500000 500000 500000 500000
Output
Copy
1
Note
In the first example Yuri can make up triangles with sides
.
In the second example Yuri can make up triangles with sides
, and.
In the third example Yuri can make up only one equilateral triangle with sides equal to
.
Solution in Python :
l = [int(i) for i in input().split()]
length = len(l)
count = 0
for a in range(l[0] , l[1]+1) :
for b in range(l[1],l[2]+1) :
for c in range(l[2] ,l[3]+1) :
if a+b > c and b+c > a and c+a > b :
count += 1
print(count)
length = len(l)
count = 0
for a in range(l[0] , l[1]+1) :
for b in range(l[1],l[2]+1) :
for c in range(l[2] ,l[3]+1) :
if a+b > c and b+c > a and c+a > b :
count += 1
print(count)
No comments:
Post a Comment