Wednesday, April 13, 2016

UVA 382: Perfection -Solution

Unknown
#include<stdio.h>
#include<math.h>

int main ()
{
    int count,list[100],k,n,limit,i,sum_of_div;
    count=0;
    while (scanf("%d",&list[count])==1)
    {
        if (list[count]==0)
        break;
        count++;
    }
    printf("PERFECTION OUTPUT\n");
    for (k=0;k<count;k++)
    {
        n=list[k];
        limit=sqrt(n)+2;
        for (i=2, sum_of_div=1;i<limit;i++)
        {
            if (n==1) sum_of_div=0;
            else if (n%i==0 && i==n/i)
                sum_of_div+=i;
            else if (n%i==0 && i<n/i)
                sum_of_div+=(i+n/i);
        }
        if (sum_of_div==n)
            printf("%5d  PERFECT\n",n);
        if (sum_of_div<n)
            printf("%5d  DEFICIENT\n",n);
        if (sum_of_div>n)
            printf("%5d  ABUNDANT\n",n);
    }
    printf("END OF OUTPUT\n");
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,