View Code of Problem 3831

#include <stdio.h>

void sort(int a[], int n);

int main() {
    int a,b,c,d;
    int i,j;
    int x, x1, m;
    int f[1000];
    while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF) {
        j=0;
        for(i=1;i<82;i++) {
            x = (a+i)*(b+i)*(c+i)*(d+i);
            x1 = x;
            m=0;
            while(x1) {
                m += x1%10;
                x1 /= 10;
            }
            if(m == i) {
                f[j++] = x;
            }
        }
        if(j==0) {
            printf("-1\n");
        }
        else {
            sort(f,j);
            printf("%d\n",f[0]);
        }
    }
}


void sort(int a[], int n) {
    int i,j;
    for(i=0;i<n-1;i++) {
        for(j=0;j<n-1-i;j++) {
            if(a[j]>a[j+1]) {
                a[j] += a[j+1];
                a[j+1] = a[j]-a[j+1];
                a[j] = a[j]-a[j+1];
            }
        }
    }
}

Double click to view unformatted code.


Back to problem 3831