题目描述
自幂数是指一个 n 位数,它的每个位上的数字的 n 次幂之和等于它本身。输入一个位数未 知的非负整数,判断该数是否为自幂数。
注:求幂函数,使用数学函数需要cmath头文件 #include<cmath> pow(n,a)求n的a次幂 例如:
int n=pow(2,4);
cout<<n;
n的值为2的4次方,n的值为16
输入
一个非负整数,0<num<100000000
输出
满足自幂数要求输出yes,否则输出no
样例
1634
yes
样例
453
no
代码展示
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,g1,z[10000]={0},i=1,s=0,n;
cin>>a;
n=a;
if(a==0)
a=a*(-1);
while(a!=0){
g1=a%10;
a=a/10;
z[i]=g1;
i++;
}
for(int j=1;j<=i;j++) s=s+pow(z[j],i-1);
if(s==n) cout<<"yes";
else cout<<"no";
return 0;
}
谢谢观看!!