"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)