Triangle Counting UVA - 11401(递推)

大白书讲的很好。。

#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
const int MAXN = 1001000;
LL n,A[MAXN];
int main()
{

    A[3] = 0;
    for(LL i=4;i<MAXN;i++)
        A[i] = A[i-1] + ((i-1)*(i-2)/2 - (i-1)/2)/2;
    while(cin>>n && n)
    {
        if(n < 3) break;
        cout<<A[n]<<endl;
    }
    return 0;
}

 

相关文章:

  • 2021-04-14
  • 2021-10-10
  • 2021-04-12
  • 2021-06-18
  • 2021-11-27
  • 2021-09-20
  • 2021-07-03
猜你喜欢
  • 2021-05-23
  • 2021-11-09
  • 2021-10-01
  • 2021-12-27
  • 2021-07-21
  • 2021-08-08
  • 2021-10-06
相关资源
相似解决方案