Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一个数的数字根和其mod 9 是关于9同余的。

Posted by Dumbear at 2009-10-22 11:04:58 on Problem 1519
So:
int get_digital_root(const char* num) {
    int res = 0;
    for (int i = 0; num[i] != '\0'; ++i)
        res = (res * 10 + num[i] - '0') % 9;
    return res == 0 ? 9 : res;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator