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 |
为什么这种方法不行呢?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator