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

why I always WA?

Posted by lcftc at 2004-09-26 16:48:43 on Problem 1844
#include<iostream>
using namespace std;
int main(){
    unsigned long N;
    while(cin>>N){

    unsigned long sum=0;
    unsigned long i;
    for(i=1;;i++){
        sum+=i;
        if(sum>=N)
            break;
    }
    unsigned int n;
    if(sum==N){
        n=i;
    }else{
        unsigned long x=sum-N;
        if(x%2==0){
            n=i;
        }else{
            n=i+2;
        }
        if(x==1){
            n=i+1;
        }
    }
        cout<<n<<endl;
    }
    return 0;
}

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