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 |
其实就是解2元一次方程啊……~~#include<iostream> #include<cmath> using namespace std; int main() { int n ; int sum; int i ; while(cin>>n) { sum = 0; i = ceil(sqrt(1+8*n))/2.0; sum = (i)*(i+1)/2; if(sum ==n) { if(i%2 ==0) cout<<"TERM "<<n<<" IS "<<i<<"/"<<"1"<<endl; else cout<<"TERM "<<n<<" IS "<<"1"<<"/"<<i<<endl; } else { sum -= i; i--; if(i%2==0) cout<<"TERM "<<n<<" IS "<<i+1-n+sum+1<<"/"<<n-sum<<endl; else cout<<"TERM "<<n<<" IS "<<n-sum<<"/"<<i+1-n+sum+1<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator