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;
	int panduan=0;
//	1000000000
//	999999999
	while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF) {
		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(i==81) {
				printf("-1\n");
			}
		}

	}

}

Double click to view unformatted code.


Back to problem 3831