解题思路:遍历从100到999的所有三位数,然后写个bool函数判断是否满足题目条件,因为只有三位数,我们可以用to_string函数先将其转换为字符串,然后得到各个位置的数,当然while也是可以的。然后就是判断是否满足即可!
注意事项:无
参考代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll qpow(ll a, ll n){ ll res =1; while(n){ if(n&1) res *= a; a *= a; n >>= 1; } return res; } bool check(int n){ string s = to_string(n); int a = s[0] - '0'; int b = s[1] - '0'; int c = s[2] - '0'; if(a*a*a+c*c*c+b*b*b == n) return true; else return false; } int main(){ for(int i=100;i<1000;i++){ if(check(i)) cout<<i<<endl; } }
0.0分
1 人评分