Guest User

06. Sum And Product

a guest
May 3rd, 2018
116
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main() {
  5. int n; cin>>n;
  6. int ed=n%10;
  7. for(int a=1;a<=9;a++){
  8.   for(int b=9;b>=a;b--) {
  9.     for(int c=0;c<=9;c++){
  10.       for(int d=9;d>=c;d--) {
  11.         if((a+b+c+d)==(a*b*c*d))
  12.           {
  13.             if(ed==5) {cout<<a<<b<<c<<d<<endl; return 1;}
  14.           }
  15.         if(((a*b*c*d)/(a+b+c+d))==3) {
  16.           if(n%3==0){
  17.             if(d>0) {cout<<d<<c<<b<<a<<endl; return 1;}
  18.           }
  19.         }
  20.          
  21.       }
  22.     }
  23.   }
  24. }
  25. cout<<"Nothing found\n";
  26.   return false;
  27. }
RAW Paste Data