We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #30: Digit Nth powers
  4. Discussions

Project Euler #30: Digit Nth powers

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • Nusratullah
    5 months ago+ 0 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;
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy