纯C

#include <stdlib.h>
#include <stdio.h>

int count(int n)
{
    if(n<=0 || n>=500000) return -1;
    int ret=0;
    for(int i=5; i<n; ++i)
    {
        int sum=0;
        for(int j=1; j<=(i/2); ++j)
        {
            if((i%j) == 0) sum+=j;
        }
        if(sum == i) ret++;
    }
    return ret;
}

int main()
{
    int out, n;
    while(scanf("%d", &n) != EOF)
    {
        out = count(n);
        if(out>=0)
            printf("%d\n", out);
        else
            return -1;
    }
    return 0;
}