#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; int end = ceil(sqrt(sqrt(1000000000))); while (scanf("%d %d %d %d", &a, &b, &c, &d) != EOF) { for (int i = 1;i <= end;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.