UVA 11401 Triangle Counting——计数原理

来源:互联网 发布:知著投资 vincent 编辑:程序博客网 时间:2024/05/21 17:12
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e6 + 10;long long a[maxn];int main() {    a[3] = 0;    for (long long x = 4; x <= maxn; x++) {        a[x] = a[x-1] + ((x-1)*(x-2)/2 - (x-1)/2)/2;    }    int n;    while (~scanf("%d", &n)) {        if (n < 3) break;        cout << a[n] << endl;    }    return 0;}

原创粉丝点击