a040. 阿姆斯壯數 5/16/2025

解法一、窮舉

✅ 完整代碼

評分結果(參考) : AC (31ms, 348KB)

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a, b;
    cin >> a >> b;

    bool space = false;
    for(int i=a; i<=b; i++){
        int digit = log10(i) + 1;
        
        int temp=i, sum=0;
        while(temp != 0){
            sum += pow(temp%10, digit);
            temp /= 10;
        }
        
        if(sum == i){
            if(space) cout << " ";
            space = true;
            cout << i;
        }
    }
    
    if(!space) cout << "none";

    return 0;
}