#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
//输入的整数最多十位数,通过递归的次数应该不会太高
int n;
int res(int temp)
{
if (temp < 10)return temp;
else
{
int m = 0;//存储temp各位数字之和
for (int i = 0; i < 10; i++)
{
m += (temp % 10);
temp = temp / 10;
}
if (m < 10)return m;
else return res(m);
};
}
int main() {
while(cin >> n)
{
cout << res(n) << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")

京公网安备 11010502036488号