Java-数三角形

数三角形

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种方法。
 
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.csdn.net/feather2016/article/details/79555396

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值