Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- /* Suma de digits de 'n' en base 4 */
- int suma_dig_4(int n)
- {
- if (n < 4) return n;
- return suma_dig_4(n/4) + n%4;
- }
- int num_dig(int n)
- {
- if (n < 10) return 1;
- return num_dig(n/10) + 1;
- }
- bool es_diabolic(int n)
- {
- return n%(2*suma_dig_4(n)) == 0;
- }
- int main()
- {
- int n;
- int cont = 0;
- while (cin >> n and n != -1) {
- if (es_diabolic(n)) ++cont;
- }
- int ndig = num_dig(cont);
- for (int i = 0; i < 6 - ndig; ++i) cout << "0";
- cout << cont << endl;
- }
Add Comment
Please, Sign In to add comment