View Code of Problem 3831

#include<stdio.h>

int S(int x) {
	int res = 0;
	while (x != 0) {
		res += x % 10;
		x /= 10;
	}
	return res;
}

int main() {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	for (int i = 1;i <= 81;i++) {
		int x = (i + a)*(i + b)*(i + c)*(i + d);
		if (S(x) == i) {
			printf("%d\n", x);
			break;
		}
		if (i ==  81) {
			printf("-1\n");
		}
	}
}

Double click to view unformatted code.


Back to problem 3831