| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:靠,这么简单的题目也会有问题!不要用模拟法。还是数学方法好。In Reply To:靠,这么简单的题目也会有问题!不要用模拟法。还是数学方法好。 Posted by:huicpc15 at 2005-11-06 16:43:56 我的数学方法
#include<iostream>
using namespace std;
#include<math.h>
main()
{
int n,m,c;
while(cin>>n&&n!=0)
{
m=(int)(sqrt(8*n+1)-1)/2;
c=m*(m+1)*(2*m+1)/6+(n-m*(m+1)/2)*(m+1);
cout<<n<<" "<<c<<endl;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator