http://47.93.249.116/problem.php?id=2173

n=3能够发现规律。最少一定是按照顺序123来   最多就是312

 

 

暴力解决就可以了  n很小   O(n)复杂度就过了

同时能够推出来公式 O(1)复杂度    注意结果为long long

 

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<numeric>
using namespace std;
#define LL long long
#define N  1006
int main()
{
    LL n;
    while(scanf("%lld",&n)!=EOF)
    {
        int t=1;
        LL s=0,sum1=0,sum2=0;
        while(t<=n)
        {
            s++;
            sum1+=s*t;
            s+=t++;
        }
        LL e=1,f=n;
        s=0;t=0;
        while(e<=f)
        {
            s+=n;
            if(t&1)
            {
                sum2+=s*e;
                s+=e++;
            }
            else
            {
                sum2+=s*f;
                s+=f--;
            }
            n--;t++;
        }
        printf("%lld %lld\n",sum1,sum2);
    }
    return 0;
}
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<numeric>
using namespace std;
#define LL long long
#define N  1006
int main()
{
    LL n;
    while(scanf("%lld",&n)!=EOF)
    {
        printf("%lld %lld\n",(3*n*n*n*n+10*n*n*n+9*n*n+2*n)/24,(7*n*n*n*n+10*n*n*n+5*n*n+2*n)/24);
    }
    return 0;
}

 

posted on 2018-08-18 19:25  云胡不喜。  阅读(180)  评论(0编辑  收藏  举报