数三角形
Time Limit: 1000 ms
Memory Limit: 65536 KiB
Problem Description
有多少种方法可以从1,2,3,4,….,n中选出3个不同的整数,使得以它们为三边长可以形成三角形?
比如n=5时有3种方法,即(2,3,4),(2,4,5),(3,4,5)。n = 8时有22种方法。
比如n=5时有3种方法,即(2,3,4),(2,4,5),(3,4,5)。n = 8时有22种方法。
Input
测试数据的第一行为整数n(3<=n<=100)。 多组输入
Output
输出其方案总数。
Sample Input
5
Sample Output
3
Hint
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int n = sc.nextInt();
long [] f = new long[105];
f[3] = 0;
for(int x = 4; x < 101; x++) {
f[x] = f[x - 1] + ((x - 1) * (x - 2) / 2 - (x - 1) / 2)/ 2;
}
if(n < 3)
break;
else
System.out.println(f[n]);
}
}
}
**https://www.cnblogs.com/rhythmic/p/5571942.html
**http://www.xuebuyuan.com/2028272.html
**https://blog.youkuaiyun.com/feather2016/article/details/79555396