View Code of Problem 3831

#include<stdio.h>
int main(){
	int a,b,c,d;
	int flag=0;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	for(int i=0;i<=1000000000;i++){
		int sx=0;
		int p=i;
		while(p>0){
			sx=sx+p%10;
			p=p/10;
		}
		int k=(sx+a)*(sx+b)*(sx+c)*(sx+d);
		if(k==i){
			printf("%d\n",i);
			flag=1;
			break;
		}
	}
	if(flag==0)printf("-1\n");
}

Double click to view unformatted code.


Back to problem 3831