View Code of Problem 3831

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
//#include <bits/stdc++.h>
using namespace std;

int s(int a) {
	int sum=0;
	while(a!=0) {
		sum=sum+a%10;
		a=a/10;
	}
	return sum;
}


int main() {
	int a,b,c,d;
//	1000000000

	while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF) {
		int panduan=0;
		for(int i=1; i<=81; i++) {
			int x=(i+a)*(i+b)*(i+c)*(i+d);
			if(s(x)==i) {
				panduan=1;
				printf("%d\n",x);
				break;
			}
		}
		if(panduan==0) {
			printf("-1\n");
		}
	}

}


Double click to view unformatted code.


Back to problem 3831