| ||||||||||
| 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()
{
long n;
while((scanf("%d",&n))==1)
{
int i;
long sum1,sum2,sum3,sum4;
for(i=0;;i++)
{
sum1=(2*i-1)*i;
sum2=(2*(i+1)-1)*(i+1);
// cout<<"sum1 is "<<sum1<<" sum2 is "<<sum2<<endl;
if(n>sum1 && n<=sum2)
break;
}
int temp1=n-sum1;
if(temp1<=2*i+1)
cout<<"TERM "<<n<<" IS "<<temp1<<"/";
else
cout<<"TERM "<<n<<" IS "<<4*i+2-temp1<<"/";
for(i=0;;i++)
{
sum3=2*i*i+i;
sum4=2*(i+1)*(i+1)+(i+1);
// cout<<"sum 3 is "<<sum3<<" sum4 is "<<sum4<<endl;
if(n>sum3 && n<=sum4)
break;
}
int temp2=n-sum3;
// cout<<"temp2 is "<<temp2<<endl;
// cout<<"and the 2*(i+1)"<<2*(i+1)<<endl;
if(temp2<=2*(i+1))
cout<<temp2<<endl;
else
cout<<4*(i+1)-temp2<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator