1178 heritage from father.cpp

来自「威士忌的HDU题解.大概有260多题的源码。对于学习非常有好处。」· C++ 代码 · 共 39 行

CPP
39
字号
/*
1178 Heritage from father
Time Limit : 1000 ms  Memory Limit : 65535 K  Output Limit : 256 K

GUN C++
*/
/*
1、这个大家都会:1+2+3+4+…n=n(n+1)/2

2、这个有些同学忘记了:
   1*1+2*2+3*3+…+n*n=n(n+1)(2n+1)/6

3、合并后得到n(n+1)(n+2)/6
*/
#include <iostream.h>
#include <math.h>
using namespace std;

const int NMAX=2147483647;
//0<N<2^31

int main()
{
    int n,ca,e;
    double total,ans;
    cout.setf(ios::fixed);
    cout.precision(2);
    while(cin>>n && n!=0)
    {
        total=(double)n*(n+1)*(n+2)/6;
        e=(int)log10(total);
        ans=total/pow(10,e);
        //cout<<total<<endl;
        cout<<ans<<"E"<<e<<endl;
    }
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?