You are viewing a single comment's thread. Return to all comments →
Let me try to explain the problem and reach out to 826 from 100
Givem k=100 , 0<=n<=100 Iterate n, for n = 0 to 100 if(f(n) is a perfect square) add to the result
(Please sum to get 826) 0 1 2 3 4 5 6 7 8 9 10 20 30 34 40 43 50 60 68 70 80 86 90 100
Naive solution: static void Main(string[] args) { long k = 100; long output = Project_Euler_171(k); }
private static long Project_Euler_171(long k) { long sum = 0; for(int i = 0; i <= k; i++) { sum += IsPowerSquare(f(i)) ? i : 0; } return sum; } private static bool IsPowerSquare(long n) { double number = (double)n; return ((double)(Math.Sqrt(number) - (long)Math.Sqrt(number))) == 0.0; } private static long f(long n) { if (n == 0) return 0; return f(n / 10) + (n % 10) * (n % 10); }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #171: Finding numbers for which the sum of the squares of the digits is a square
You are viewing a single comment's thread. Return to all comments →
Let me try to explain the problem and reach out to 826 from 100
Givem k=100 , 0<=n<=100 Iterate n, for n = 0 to 100 if(f(n) is a perfect square) add to the result
(Please sum to get 826) 0 1 2 3 4 5 6 7 8 9 10 20 30 34 40 43 50 60 68 70 80 86 90 100
Naive solution: static void Main(string[] args) { long k = 100; long output = Project_Euler_171(k); }