Hangzhou Electric Acm1163--eddy ' s digital Roots

Source: Internet
Author: User

The main problem is to find the law, the first time to find out! ~~

The topic is to ask for a number of digital root, this so-called digital root is a number of the sum of the numbers, if the number of double digits, repeat the digital root, until the number is a number.

This problem is to seek n^n 's digital root.

The rules are as follows:

The result of N-n multiplication is assumed to be the multiplication of the digital root of s,s, which is equal to the number of n digital root.

The following is the AC code, very simple:

#include <iostream>using namespace Std;int main () {int I, J, N;while (Cin >> N, N) {j = n;int M;while (J >= 10)                 //For digital root{m of n for input = 0;while (j) {m + = j% 10;j/= 10;} j = m;} m = j;for (i = 1; i < n; i++)        //Cyclic n-1 Solution {j = J * M;int K;while (J >=) {k = 0;while (j) {k + = j% 10;j/= 10;} j = k;}} cout << J << Endl;} return 0;}


Hangzhou Electric Acm1163--eddy ' s digital Roots

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.