UVA Solution 382 - Perfection - Solution in C, C++ | Volume 3 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Friday, May 5, 2017

UVA Solution 382 - Perfection - Solution in C, C++ | Volume 3

UVA Solution 382 - Perfection - Solution in C, C++ | Volume 3


UVA Online Judge Solution 382 - Perfection| Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=318

Problem Name: 382 - Perfection
Problem Number : UVA - 382 - Perfection
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 382 - Perfection - Solution in C, C++ | Volume 3


UVA Solution 382 - Perfection Code in C, CPP:


#include<stdio.h>
#include<math.h>
int main() {
 int x;
 puts("PERFECTION OUTPUT");
 while(scanf("%d", &x) == 1 && x) {
  int i, j;
  int sum = 1, sq = (int)sqrt(x);
  for(i = 2; i <= sq; i++) {
   if(x%i == 0) {
    j = x/i;
    sum += i+j;
   }
  }
  printf("%5d  ", x);
  if(x == 1)    puts("DEFICIENT");
  else if(sum == x) puts("PERFECT");
  else if(sum < x) puts("DEFICIENT");
  else    puts("ABUNDANT");
 }
 puts("END OF OUTPUT");
    return 0;
}

No comments:

Post a Comment