asgarlikanan

https://www.e-olymp.com/az/problems/1461

Aug 19th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 0.42 KB | None | 0 0
  1. /*
  2.     Author: Kanan Asgarli
  3.     https://www.e-olymp.com/az/problems/1461
  4. */
  5. #include <iostream>
  6. #include <algorithm>
  7. using namespace std;
  8. int f(int n){
  9.     if(n == 0)
  10.         return 1;
  11.     return n%10*f(n/10);
  12. }
  13. int n, m, k, maxi = 1000000000, ans;
  14. int main()
  15. {
  16.    
  17.     cin>>n>>k;
  18.     for(int i = 0; i < n; i++){
  19.         cin>>m;
  20.         if(maxi > abs(f(m)-k)){
  21.             maxi = abs(f(m)-k);
  22.             ans = m;
  23.         }
  24.     }
  25.     cout<<ans<<endl;
  26.     return 0;
  27. }
Add Comment
Please, Sign In to add comment