COEX05-Editorial

PROBLEM LINKS:
Practice
Contest

DIFFICULTY:
Easy

PREREQUISITES:
None

PROBLEM:
Add all the digits of the given number until you get a single digit number.
This problem is also known as the digital root problem.

EXPLANATION:
For finding digital root, the following formula exists:
((n-1)%9)+1)

AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here.
Tester’s solution can be found here.

//C++ gcc 4.9.2
#include
using namespace std;
int main()
{int n;
cin>>n;
cout<<((n-1)%9)+1<<endl;
return 0;
}