O(N)分成1,2与3,4两部分搞一搞。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,ans=0,lim; int ask(int x) { return min(lim,x-1)-max(x-lim,1)+1; } int main() { scanf("%d",&n);lim=n/2-(!(n&1)); for (int i=2;i<=n-2;i++) ans+=ask(i)*ask(n-i); printf("%d\n",ans); return 0; }