有点小郁闷,把5d弄成了-5d,wa了一次。不用想太多,只要直接枚举就行了。
Accepted | 1284 | C | 00:00.01 | 392K |
#include<stdio.h>
void solve(int n)
{
printf("%5d " ,n);
int i,res = 0 ;
for (i = 1; i <= n/2; i++ )
if (n % i == 0) res += i;
if (res == n) printf("PERFECT/n" );
else if (res < n) printf("DEFICIENT/n" );
else if (res > n) printf("ABUNDANT/n" );
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("1284.txt","r" ,stdin);
#endif
int n;
printf("PERFECTION OUTPUT/n" );
while (scanf("%d",&n) != EOF && n != 0 )
solve(n);
printf("END OF OUTPUT/n" );
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
}
void solve(int n)
{
printf("%5d " ,n);
int i,res = 0 ;
for (i = 1; i <= n/2; i++ )
if (n % i == 0) res += i;
if (res == n) printf("PERFECT/n" );
else if (res < n) printf("DEFICIENT/n" );
else if (res > n) printf("ABUNDANT/n" );
}
void main()
{
#ifndef ONLINE_JUDGE
freopen("1284.txt","r" ,stdin);
#endif
int n;
printf("PERFECTION OUTPUT/n" );
while (scanf("%d",&n) != EOF && n != 0 )
solve(n);
printf("END OF OUTPUT/n" );
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
}