这类问题一般都有固定的公式,告诉大家一个技巧:二维的一般是f(x)=a*x^2+b*x+c,三维的一般是f(x)=a*x^3+b*x^2+c*x+d. 用带定系数法求出各个系数就行了。
http://acm.hdu.edu.cn/showproblem.php?pid=1290
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include
"
iostream
"
using namespace std;
int main()
{
int n;
while (cin >> n)
{
cout << (n * n * n + 5 * n + 6 ) / 6 << endl;
}
return 0 ;
}
using namespace std;
int main()
{
int n;
while (cin >> n)
{
cout << (n * n * n + 5 * n + 6 ) / 6 << endl;
}
return 0 ;
}