思路:反正我推不出这公式。。。。root(ab*cd) = a*c+a*d+b*c+b*d = (a+b)*(c+d);
代码如下:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
int boot(int n)
{
int m,sum,a;
sum=0;
while(n)
{
sum+=n%10;
n/=10;
}
if(sum>=10)
boot(sum);
else
return sum;
}
int main()
{
int n;
int k;
int m;
while(scanf("%d",&n) && n)
{
k=boot(n);
m=1;
while(n--)
{
m=boot(m*k);
}
printf("%d\n",m);
}
return 0;
}
本文介绍了一种通过迭代计算数字根的方法。该方法接收一个整数作为输入,并反复计算其各位数字之和直至得到一位数的数字根。文章提供了一个完整的C++实现示例,包括一个名为`boot`的函数用于计算数字根,以及主函数中应用此函数进行迭代的过程。

709

被折叠的 条评论
为什么被折叠?



