View Code of Problem 93

#include <iostream>
using namespace std;

int sum(int n){
    int s=0;
    for(int j=1;j<n;j++){
        if(n%j==0)
            s+=j;
    }
    return s;
}

int main(){
    int a,b,s1=0,x[10000],k=0,flag;
    scanf("%d%d",&a,&b);
    for(int j=a;j<=b;j++){
        flag = 0;
        s1=sum(j);
        x[k++] = s1;
        for(int l=0;l<k;l++){
            if(x[l]==j)
                flag = 1;
        }
        if(flag==1)
            continue;
        if(sum(s1)==j&&s1>=a&&s1<=b&&s1!=j)
            printf("%d %d\n",j,s1);
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 93