You are viewing a single comment's thread. Return to all comments →
//C# using System;
class Program { static int PowerSum(int num, int power) { int sum = 0; int temp = num;
while (temp > 0) { int digit = temp % 10; sum += (int)Math.Pow(digit, power); temp /= 10; } return sum; } static void Main() { int N = int.Parse(Console.ReadLine()); int totalSum = 0; for (int i = 10; i <= 999999; i++) { if (i == PowerSum(i, N)) { totalSum += i; } } Console.WriteLine(totalSum); }
}
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# using System;
class Program { static int PowerSum(int num, int power) { int sum = 0; int temp = num;
}