ENTRENAMIENTO

NUMEROS AMIGOS

 

// @BEGIN_OF_SOURCE_CODE
/*
victord2exp!!!
victord2exp.blogspot.com
victord2exp.tk
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL long long

#define For(i, a, b) for( int i = (a); i < (b); i++ )
#define Fors(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fore(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define Set(a, s) memset(a, s, sizeof (a))
#define Read(r) freopen(r, "r", stdin)
#define Write(w) freopen(w, "w", stdout)
using namespace std;
int sumDiv(int n){
    int s=1;
    for(int i=2;i<=n/2;i++)
        if(n%i==0)
            s+=i;
    return s;
}
int main ()
{
    //Read(".in");
    int lim=1000;
    for(int n=0;n<=lim;n++){
        int s = sumDiv(n);
        int t = sumDiv(s);
        if(n==t)
            cout<<n<<endl;
    }
    return 0;
}

Tutorial de Topcoder

http://marcelodata.blogspot.com/2012/02/topcoder-el-mejor-gimnasio-para....

 

Tags: