Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

其实就是解2元一次方程啊……~~

Posted by visual at 2006-04-20 12:38:18 on Problem 1969
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator