CSU 1759: Triangle(选三条边构成三角形的计数问题)

xiaoxiao2021-02-28  77

题目:

Description

给你长度为1~n n条边,请你求出有多少种组合方法数可以选出三条边构成三角形

Input

多组数据输入输出(数据组数考虑为最大可能性)每组数据输入一个正整数n,表示有n条长度的边可供选择(n<=10000)

Output

每组数据输出可构成三角形的边的选择方法数

Sample Input

2 4

Sample Output

0 1

代码:

#include<iostream> using namespace std; int main() { long long n; while (cin >> n)cout << ((n - 1)*(n - 2)*(n - 3) / 6 + (n - 1) / 2 * (n / 2 - 1)) / 2 << endl; return 0; }

转载请注明原文地址: https://www.6miu.com/read-2622498.html

最新回复(0)