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

用函数就一切OK!!!

Posted by 90405129 at 2004-12-27 14:14:27 on Problem 2140
In Reply To:怎么才能不超时???我已经很费力了!!! Posted by:90405129 at 2004-12-21 19:48:28
#include<stdio.h>
int f(int n){
      int s=0,i,j,sum;
      for(i=1;i<=n;i++){
          sum=0;
          for(j=i;j<=n;j++){
               sum+=j;
               if(sum==n){s++;break;}
               if(sum>n)break;
		  }
	  }

       return (s);
}
void main(){
     int n;
     scanf("%d",&n);
     printf("%d\n",f(n));
}

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