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

为什么这种方法不行呢?

Posted by xianyunsc at 2005-08-21 21:53:36 on Problem 1528
#include<stdio.h>
#include<math.h>
int main()
{
    int n;
    printf("PERFECTION OUTPUT\n");
    while(scanf("%d",&n)&&n)
    {
        int t = sqrt(n);                   
        int ans = 0;
        for(int i = 1; i <= t; i++)
            if(n%i==0)                     
            {                             
                ans+=i;             
             if(n!=i*i&&i!=1) ans+=(n/i);    
              // 避免当 n=i*i 时,i加重复了; i=1 时也要排除
                 
            }
      if(ans > n)       printf("%5d  ABUNDANT\n",n);
       else if(ans < n)  printf("%5d  DEFICIENT\n",n);
       else              printf("%5d  PERFECT\n",n);
    }
    printf("END OF OUTPUT\n");
  return 0;
}                 
算 n 的因子,只需算到 sqrt(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