View Code of Problem 3831

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int s(int x){
	int cnt=0;
	while(x>0){
		cnt=cnt+x%10;
		x/=10;
	}
	return cnt;
} 
int main(){
	ll x,j;
	int a,b,c,d,flag=0;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(x=1;x<=1000000000;x++){
		if(x==(s(x)+a)*(s(x)+b)*(s(x)+c)*(s(x)+d)){
			printf("%d\n",x);
			flag=1;
			break;
		}
	}
	if(flag==0) printf("-1\n");
	return 0;
} 

Double click to view unformatted code.


Back to problem 3831