problem link :
Discussion: just simply make divisor and add them and follow the instruction of problem. make right align with %5 specifier..
try yourself before see the code.
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,i,j,m,p,q,d,k,l,sum;
vector<long long> vec;
vector<long long>result;
while(cin >>n)
{
if(n==0)
break;
vec.push_back(n);
}
m=vec.size();
printf("PERFECTION OUTPUT\n");
for(k=0;k<m;k++)
{
p=vec[k];
result.clear();
for(i=1;i<sqrt(p);i++)
{
if(p%i==0)
{
if(p/i==i)
result.push_back(i);
else
{
result.push_back(i);
result.push_back(p/i);
}
}
}
l=result.size();
sum=0;
for(i=0;i<l;i++)
{
sum+=result[i];
}
sum-=vec[k];
if(sum==vec[k])
printf("%5lld PERFECT\n",vec[k]);
else if(sum<vec[k])
printf("%5lld DEFICIENT\n",vec[k]);
else if(sum>vec[k])
printf("%5lld ABUNDANT\n",vec[k]);
}
printf("END OF OUTPUT\n");
return 0;
}
No comments:
Post a Comment