Hdoj 1163 Eddy ' s digital Roots (simple number theory)

Source: Internet
Author: User

"Idea":http://blog.csdn.net/iamskying/article/details/4738838

Solution Ideas:

Now to analyze a problem, assuming that the 10-bit number is a, and the single-digit is an integer of B as AB, it is deduced
Ab*ab = (a*10+b) * (a*10+b) = 100*a*a+10*2*a*b+b*b
According to the formula available: root (ab*ab) = A*a+2*a*b+b*b = (a+b) * (A+B); [Formula I]
The same can be proven: root (Ab*ab*ab) = (a+b) * (a+b) * (A+B); [Formula Two]
It can be seen that the root of the total product of n identical integers = the product of the root of each element


Set another integer CD, and Cd!=ab
AB*CD = (a*10+b) * (c*10+d) = 100*a*c+10* (a*d+b*c) +b*d
According to the formula available: root (AB*CD) = A*c+a*d+b*c+b*d = (a+b) * (C+D); [Formula Three]
Visible, for two different integers are also established.


Finally, the results obtained above are generalized as follows:
The number of the total value of n integers = the product of the number root of each item element

Tip: The subject simply depends on the [Formula Three] can be AC.

Note: The idea is indeed the Formula Two, but the middle process using Formula Two will overflow, so must pass equation three. (same as thought)

"AC Code":

#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath > #include <iomanip> #include <algorithm>using namespace std;/* run this program using the console Pauser or Add your own Getch, System ("pause") or input loop */int getroot (int n) {while (n >=) {int sum = 0;while (n) {sum + = n%1 0;n/= 10;} n = sum;} return n;} int main (int argc, char** argv) {//freopen ("In.txt", "R", stdin);//freopen ("OUT.txt", "w", stdout); int n = 0;while (cin &G t;> n && N) {int root = Getroot (n); int i = 0, Mul = 1;for (i = 0; i < n; i++) Mul = Getroot (Root*mul); cout &L t;< getroot (mul) << Endl; }return 0;}


Hdoj 1163 Eddy ' s digital Roots (simple number theory)

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.