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 |
0msACIn Reply To:Re:水,用数学水之 Posted by:_leaf_ at 2009-07-29 00:12:15 > 如何用数学水啊~~~~~O(1)了都。。。。 #include<iostream> #include<math.h> using namespace std; int fun(int n) { double k; k=sqrt(double(2)*n+0.25)-0.5; if(k==int(k)) return int(k)-1; else return int(k); } int main() { int k,m,n; while(cin>>n) { k=fun(n); m=n-k*(k+1)/2; if(k%2) cout<<"TERM "<<n<<" IS "<<m<<'/'<<k+2-m<<endl; else cout<<"TERM "<<n<<" IS "<<k+2-m<<'/'<<m<<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