You are viewing a single comment's thread. Return to all comments →
C++
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(10); for (int i=0; i<=9; i++) { int p = pow(i, n); arr[i] = p; } int S = 0; for (int i=100; i<1000000; i++) { int num = i, sum=0; while(num>0) { int z = num%10; sum = sum+arr[z]; num = num/10; } if (sum==i) S = S + sum; } cout << S; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #30: Digit Nth powers
You are viewing a single comment's thread. Return to all comments →
C++