#include <iostream>
#include <algorithm>
#include <cstring>
template <typename T>
T digital_root(T n)
{
return n - 9 * ((n - 1) / 9);
}
template <typename T>
T digital_root(char *arr)
{
T n = 0;
std::for_each(arr, arr + strlen(arr), [&n](char c){ n += c; });
return digital_root<T>(n);
}
int main ()
{
// 593478:
// 5 + 9 + 3 + 4 + 7 + 8 = 36
// 3 + 6 = 9
int x1 = 593478;
std::cout << digital_root<int>(x1) << std::endl;
char x2[] = "593478";
std::cout << digital_root<int>(x2) << std::endl;
return 0;
}