不知道为什么0和1不算
通过计算发现当数字超过7位时5次方数就不存在(以为7个9的五次方还是6位)所以确定枚举上限简化时间复杂度
在通过第一次输出得到所以答案再优化一次枚举上限进一步简化时间复杂度
ac代码如下,
#include <iostream> using namespace std; int n; int wucifang(int x){ return x*x*x*x*x; } int main() { //cout<<wucifang(9)*7<<endl;//确定枚举上限 for(int i=2;i<=200000;i++){ int sum=0,t=i; while(t){ sum+=wucifang(t%10); t/=10; } if(sum==i) cout<<i<<endl; } return 0; }