Problem:
Problem B:
完全数
ある整数
N
に対し，その数自身を除く約数の和を
S
とする．
N
=
S
のとき
N
は完全数 (perfect number)，
N
>
S
のとき
N
は不足数 (deficient number)，
N
<
S
のとき
N
は過剰数 (abundant number) と呼ばれる．
    与えられた整数が，完全数・不足数・過剰数のどれであるかを
    判定するプログラムを作成せよ．
プログラムの実行時間が制限時間を越えないように注意すること．
Input
入力はデータセットの並びからなる．
    データセットの数は 100 以下である．
各データセットは整数
N
(0 <
N
≤ 100000000) のみを含む1行からなる．
最後のデータセットの後に，入力の終わりを示す 0 と書かれた1行がある．
Output
各データセットに対し，
    整数
N
が完全数ならば “
perfect number
”，
    不足数ならば “
deficient number
”，
    過剰数ならば “
abundant number
” という文字列を
    1行に出力せよ．
Sample Input
1
2
3
4
6
12
16
28
33550336
99999998
99999999
100000000
0
Output for the Sample Input
deficient number
deficient number
deficient number
deficient number
perfect number
abundant number
deficient number
perfect number
perfect number
deficient number
deficient number
abundant number

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef vector<pair<int,int> > pr;
const int H_MX = 100000001;

int N;
pr v;
vector<int> prime;
unsigned int bset[H_MX/32+1] = {0};

bool get_b(int i){
	int bank = i / 32;
	int ofs = i % 32;
	return bset[bank] & (1<<ofs);
}
void set_b(int i){
	int bank = i / 32;
	int ofs = i % 32;
	bset[bank] |= (1<<ofs);
}

void hurui(){
	for(int i = 2; i < H_MX; i++){
		if(get_b(i) == false){
			prime.push_back(i);
			for(int j = i; j < H_MX; j+=i){
				set_b(j);
			}
		}
	}
}

void factor(int n,pr &p){
	for(int i = 0; i < prime.size(); i++){
		bool first = true;
		while(n % prime[i] == 0){
			if(first){
				p.push_back(make_pair(prime[i],1));
			}
			else{
				p[p.size()-1].second++;
			}
			n /= prime[i];
			first = false;
		}
		if(n <= 1) return;
	}
}
int calc(int n,const pr &p){
	long long S = 1;
	for(int i = 0; i < p.size(); i++){
		long long tmp = 0;
		for(int j = 0; j <= p[i].second; j++){
			tmp += pow(p[i].first,j);
		}
		S *= tmp;
		if(S - n > n){
			return n+1;
		}
	}
	return (int)(S - n);
}


int main(){
	hurui();
	while(cin >> N,N != 0){
		v = pr();
		factor(N,v);
		int S = calc(N,v);
		if(N == S){
			cout << "perfect number" << endl;
		}
		else if(N > S){
			cout << "deficient number" << endl;
		}
		else{
			cout << "abundant number" << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 1460
memory_kb: 47772
final_rank: 20

code_snippet: #include<iostream>
#include<cmath>
#include<vector>
using namespace std;

bool judgePrimeNumber( int a )
{
    for( int i = 2; i <= sqrt(a); i++ )
        if( a % i == 0 )
            return false;
    return true;
}

int power( int a, int b )
{
    if( b == 0 )
        return 1;
    int c = 1;
    for( int i = 0; i < b; i++ )
        c *= a;
    return c;
}

struct divisor
{
    int value, cnt;
};

int main()
{
    int n, m;
    vector<divisor> v(100);

    while( cin >> n )
    {
        if( n == 0 )
            break;

        m = n;

        for( int i = 0; i < v.size(); i++ )
        {
            v[i].value = 0;
            v[i].cnt = 0;
        }

        if( judgePrimeNumber(n) == 1 )
            cout << "deficient number" << endl;
        else
        {
            while( n != 1 )
            {
                for( int i = 2; i <= n; i++ )
                    if( n % i == 0 )
                    {
                        for( int j = 0; j < v.size(); j++ )
                        {
                            if( v[j].value == 0 )
                            {
                                v[j].value = i;
                                v[j].cnt++;
                                break;
                            }
                            if( v[j].value == i )
                            {
                                v[j].cnt++;
                                break;
                            }
                        }
                        n /= i;
                        break;
                    }
            }

            int dcnt = 0;
            for( int i = 0; i < v.size(); i++ )
            {
                if( v[i].value == 0 )
                    break;
                dcnt++;
            }

            int div[dcnt], res = 0;
            for( int i = 0; i < dcnt; i++ )
                div[i] = 0;
            while( 1 )
            {
                bool judge = false;
                for( int i = 0; i < dcnt; i++ )
                    if( v[i].cnt != div[i] )
                        judge = true;
                
                int sum = 1;
                for( int i = 0; i < dcnt; i++ )
                    sum *= power( v[i].value, div[i] );

                res += sum;

                if( judge == false )
                    break;

                div[0]++;
                for( int i = 0; i < dcnt; i++ )
                {
                    if( div[i] > v[i].cnt )
                    {
                        div[i] = 0;
                        div[i+1]++;
                    }
                }
            }
            if( res - m < m )
                cout << "deficient number" << endl;
            else if( res - m > m )
                cout << "abundant number" << endl;
            else
                cout << "perfect number" << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 380
memory_kb: 3008
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){

  int n,ans,i,ika;
  
  scanf("%d",&n);
  while(n != 0){
    
    ika = n;
    i = 2;
    if(n == 1)ans = 0;
    else ans = 1;
    
    while(ika > i){
      
      if(n%i == 0){
	ans += i;
	if(i*i != n) ans += n/i;
	ika = n/i;
      }
      
      i++;
    }
    
    if(ans == n) printf("perfect number\n");
    else if(ans < n) printf("deficient number\n");
    else if(ans > n) printf("abundant number\n");
    scanf("%d",&n);
  }
  
  return (0);
}
accuracy: 1
time_ms: 1060
memory_kb: 3056
final_rank: 15

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
	long long  a = 6;
	while (cin >> a&&a != 0) {
		long long sum = 1,a2=a;
		int i = 2;
		while (a != 1) {
			if (a%i == 0) {
				int j = 1;
				long long sum2 = 1;
				while (a%i == 0) {
					sum2 += (pow(i, j));
					j++;
					a /= i;
				}
				sum *= sum2;
			}
			if(i==2)
				i++;
			else i += 2;
		}
		sum -= a2;
		if (a2 == sum) cout << "perfect number" << endl;
		else if (a2 > sum) cout << "deficient number" << endl;
		else cout << "abundant number" << endl;
	}
}
accuracy: 1
time_ms: 1670
memory_kb: 3200
final_rank: 18

code_snippet: #include<stdio.h>
#include<iostream>
#include<fstream>
#include<stack>
#include<math.h>

using namespace std;



int main(){

	int n;
	while (cin >> n, n){
		if (n < 2){
			cout << "deficient number" << endl;
			continue;
		}

		int s = 1;
		for (int i = 2; i <= sqrt(n); i++){
			if (n%i == 0 && i == sqrt(n) && n / sqrt(n) == sqrt(n)){
				s += i;
			}
			else if (n%i == 0){
				s += i;
				s += n / i;
			}
		}

		if (n == s)cout << "perfect number" << endl;
		if (n > s)cout << "deficient number" << endl;
		if (n < s)cout << "abundant number" << endl;

	}

	return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for(int n; cin >> n&&n;){
		int s = 0;	s -= n;
		for (int i = 1; i <= sqrt(n); i++) {
			if (n%i == 0) {
				s += n / i;
				if (n != 1 && i != n / i) s += i;
			}
		}

		if (n == s)
			cout << "perfect number" << endl;
		else if (n > s)
			cout << "deficient number" << endl;
		else
			cout << "abundant number" << endl;

	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main(void) {
	while (true) {
		int n; cin >> n;
		if (n == 0)break;


		int s = 0;	s -= n;
		for (int i = 1; i <= sqrt(n); i++) {
			if (n%i == 0) {
				s += n / i;
				if (n != 1 && i != n / i) s += i;
			}
		}
		//cout << s << endl;

		if (n == s)
			cout << "perfect number" << endl;
		else if (n > s)
			cout << "deficient number" << endl;
		else
			cout << "abundant number" << endl;

	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include<iostream>
#include<string>
using namespace std;
int n;

string hantei(int n) {
	int sum = 0;
	for (int i = 1; i <= n / 4; i++) {
		if (n%i == 0) { sum += i; }
	}
	if (n % 3 == 0) { sum += n / 3; }
	if (n % 2 == 0) { sum += n / 2; }
	if (sum < n) { return "deficient number"; }
	if (sum == n) { return "perfect number"; }
	return "abundant number";
}

int main() {
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		cout << hantei(n) << endl;
	}
}
accuracy: 1
time_ms: 2340
memory_kb: 3060
final_rank: 19

code_snippet: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
 
const int INF = 1000000;
 
 
 
 
int main() {
	ll n;
	while(cin >> n){
		if(n == 0LL) break;
		else if (n == 1LL) {
			cout << "deficient number" << endl;
			continue;
		}
		ll a = 1LL;
		for (ll i = 2LL; i * i <= n; i += 1) {
			if (n % i == 0) {
				a += n / i;
				a += i;
			}
			if (n == (ll)i * i) {
				a -= i;
			}
		}
		//cout << a << endl;
		string ans;
		if (a < n) ans = "deficient number";
		else if (a == n) ans = "perfect number";
		else ans = "abundant number";
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1188
final_rank: 13

code_snippet: #include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long s,n;
	while(cin>>n,n){
		s=1;
		loop(i,2,sqrt(n))if(n%i==0){s+=i;s+=(n/i);}
		if(n==1)cout<<"deficient number"<<endl;
		else if(n>s)cout<<"deficient number"<<endl;
		else if(n<s)cout<<"abundant number"<<endl;
		else cout<<"perfect number"<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include<iostream>
#include<cmath>
using namespace std;

int main(){
  int n, sum;
  while(cin >> n, n){
    int N = n;
    sum = 1;
    for(int i = 1; i <= n; i++){
      if(n % i == 0) {
	  int j = 1, temp = 1;
	  while(n % i == 0 && i != 1){
	    n /= i;
	    temp += (int)pow(i,j++);
	  }
	  //	  cout <<"temp"<< temp << endl;
	  sum *= temp;
      }
    }
    sum -= N;
    //        cout << sum << endl;
    if(sum > N) cout << "abundant number" << endl;
    else if(sum < N) cout << "deficient number" << endl;
    else cout << "perfect number" << endl;

    
  }
  return 0;
}
accuracy: 1
time_ms: 1680
memory_kb: 1200
final_rank: 17

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

int main() {
	ll N;
	while(cin >> N, N) {
		ll cnt = (N==1 ? 0 : 1);
		for(int i=2; i*i<=N; i++) {
			if(N%i == 0) {
				cnt += i + (N/i);
				if(i == N/i) cnt -= i;
			}
		}
		if(cnt == N) {
			cout << "perfect number" << endl;
		}
		else if(cnt < N) {
			cout << "deficient number" << endl;
		}
		else {
			cout << "abundant number" << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  long long n;
  while(cin >> n){
    if(n==0)break;

    long long sum = n==1?0:1;
    for(long long i=2;i*i<=n;i++){
      if(n%i == 0){
	sum += i;
	if(i*i!=n)sum += n/i;
      }
    }

    if(sum<n)cout << "deficient number" << endl;
    else if(sum>n)cout << "abundant number" << endl;
    else cout << "perfect number" << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1152
final_rank: 1

code_snippet: //テストケース100個以下、1 <= n <= 10^8
#include<iostream>
#include<cmath>
using namespace std;

char *out[3] = {"perfect number", "deficient number", "abundant number"};

int main() {
	int n;
	while( cin >> n ) {
		if (!n) break;
		
		int i, s = 0;
		for( i = 1; i <= (int)(sqrt((double)n) + 1e-6); i++ ) {
			if ( n % i == 0 ) {
				s += i;
				if ( n/i > i )
					s += n/i;
			}
		}
		s -= n;
		//cout << s << endl;
		
		if ( n == s )
			cout << out[0] << endl;
		if ( n > s )
			cout << out[1] << endl;
		if ( n < s )
			cout << out[2] << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        
        int sum=0;
        for(int i=1;i<=sqrt(n);i++){
            if(n%i==0){
                if(i!=n)sum+=i;
                if(i*i!=n && i!=1)sum+=n/i;
            }
        }
        if(sum==n)cout<<"perfect number"<<endl;
        else if(sum<n)cout<<"deficient number"<<endl;
        else if(sum>n)cout<<"abundant number"<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include<cstdio>
#include<set>
#include<cmath>
#include<iostream>
using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n),n)
    {
        set<int> s;
        s.insert(1);
        for(int i=2;i<sqrt(1.0*n)+2;i++)
        {
            if(n%i == 0)
            {
                s.insert(i);
                s.insert(n/i);
            }
        }
        set<int>::iterator p;
        int sum = 0;
        for(p=s.begin();p!=s.end();p++)
        {
            //cout<<*p<<endl;
            sum += *p;
        }
        if(n<=4) printf("deficient number\n");
        else{
             if(sum > n) printf("abundant number\n");
             else if(sum == n) printf("perfect number\n");
             else printf("deficient number\n");
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1172
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

string dn = "deficient number";
string pn = "perfect number";
string an = "abundant number";

int main() {

  for (int n;cin>>n,n;) {
    int pr = 1;
    int n0 = n;
    for (int m = 2; m <= n; ++m) {
      int cx = 0;
      while (n % m == 0) {
        n /= m;
        ++cx;
      }
      if (cx > 0) {
        pr *= (pow(m, cx + 1) - 1) / (m - 1);
      }
    }
    if (pr < 2 * n0) {
      cout << dn << endl;
    } else if (pr == 2 * n0) {
      cout << pn << endl;
    } else {
      cout << an << endl;
    }
  }

  return 0;
}
accuracy: 1
time_ms: 1200
memory_kb: 1248
final_rank: 16

code_snippet: #include <iostream>
#include <cmath>

using namespace std;

int main(){
	int n;
	int i;
	while(true){
		double s=0.0;
		cin >> n;
		if(n==0) break;
		bool flag=false;
		//約数列挙
		for(i=1;i<sqrt(n);i++){
	//		cout << i;
			if(n%i==0){
				s+=i;
				s+=(n/i);
				if(s<0){
					flag = true;
					break;
				}
//				cout << i << endl;
//				cout << (n/i) << endl;
			}
		}
		s-=n;
		if((double)n<s || flag) cout << "abundant number" << endl;
		else if((double)n>s) cout << "deficient number" << endl;
		else if((double)n==s) cout << "perfect number" << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  long long int in;
  while(cin>>in,in){
    long long int sum=0;
    double tmp=sqrt(in);
    int co;
    if(tmp-(int)tmp!=0.0)co=(int)tmp+1;
    else co=(int)tmp+2;
    loop(i,1,co)if(in%i==0){
      if(in!=i*i)sum+=in/i+i;
      else sum+=i;
    }
    sum-=in;
    if(sum==in)cout<<"perfect number"<<endl;
    else if(sum<in)cout<<"deficient number"<<endl;
    else cout<<"abundant number"<<endl;
  }


}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2

code_snippet: #include<iostream>
#include<cmath>
using namespace std;
int main (){

  int n,a,b;

  while(1){

    a=0;
    
    cin >>n;
    
    if( n == 0 )break;

    for(int i=1; i <=  sqrt(n) ; i++){
      if( n%i == 0){
	if( i == n/i){
	  a+=i;
	}else{
	  a+=i+n/i;
	}      
      }
    }
    
    
    b=a-n;

    if( n == 1 ){
      b=0;
    }

    if( n == b ){
      cout <<"perfect number"<<endl;
    }else if( n > b ){
      cout <<"deficient number"<<endl;
    }else if( n < b ){
      cout <<"abundant number"<<endl;
    }

  }
    


  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 2