| ||||||||||
| 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 | |||||||||
代码数字大了就输出有错,麻烦看看问题
#include <iostream>
using namespace std;
int main(){
unsigned long i;
int num;
int s1;
unsigned long j;
cin>>num;
while(num--){
cin>>i;
s1=1;
if (i==1 || i==2)//最开始的3个就特殊处理
{
cout<<1<<endl;
break;
}
if (i==3)
{
cout<<2<<endl;
break;
}
j=1;
while(1){
if (j*(j+1)>=2*i)//等差数列求和公式
{
break;
}
else
{
s1=j*(j+1)/2;
}
j++;
}
i=i-s1;
if (i==0)
{
cout<<j<<endl;
}
else
{
cout<<i<<endl;
}
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator