Nathan Coulas

CCC '96 S1 - Deficient, Perfect, and Abundant

ccc96s1 CPP17 25 Feb, 2020 0.059s 5 points

Source Code

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

template<class C>constexpr int sz(const C&c){return int(c.size());}

using ll=long long;constexpr const char nl='\n',sp=' ';




void check(int n){
	std::vector< int > collect;
	int c = 1,  s = 0;
	collect.push_back(1);
	for(int i = 2; i < n; i++){
		if(n % i == 0){
			c++;
			collect.push_back(i);
		}
	}

	for(int i = 0; i < collect.size(); i++){
				s += collect[i];
	}

	if(s < n){
		cout << n << " is a deficient number." << endl;
	}else{
		if(s == n){
			cout << n << " is a perfect number." << endl;
		}else{
			cout << n << " is an abundant number." << endl;
		}

	}

}

  int main(){
      ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

      int n, temp;
      cin >> n;
      for(int i = 0; i < n; i++){
    	  cin >> temp;
    	  check(temp);
      }

  }