Guest User

Untitled

a guest
Jul 15th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. /* Suma de digits de 'n' en base 4 */
  5. int suma_dig_4(int n)
  6. {
  7.   if (n < 4) return n;
  8.   return suma_dig_4(n/4) + n%4;
  9. }
  10.  
  11. int num_dig(int n)
  12. {
  13.   if (n < 10) return 1;
  14.   return num_dig(n/10) + 1;
  15. }
  16.  
  17. bool es_diabolic(int n)
  18. {
  19.   return n%(2*suma_dig_4(n)) == 0;
  20. }
  21.  
  22. int main()
  23. {
  24.  int n;
  25.  int cont = 0;
  26.  while (cin >> n and n != -1) {
  27.    if (es_diabolic(n)) ++cont;
  28.  }
  29.  int ndig = num_dig(cont);
  30.  for (int i = 0; i < 6 - ndig; ++i) cout << "0";
  31.  cout << cont << endl;
  32. }
Add Comment
Please, Sign In to add comment