Problem:
Dudeney Number

　

A Dudeney number is a positive integer for which the sum of its decimal digits is equal to the cube root of the number. For example, $512$ is a Dudeney number because it is the cube of $8$, which is the sum of its decimal digits ($5 + 1 + 2$).

In this problem, we think of a type similar to Dudeney numbers and try to enumerate them.

Given a non-negative integer $a$, an integer $n$ greater than or equal to 2 and an upper limit $m$, make a program to enumerate all $x$’s such that the sum of its decimal digits $y$ satisfies the relation $x = (y + a)^n$, and $x \leq m$.

Input

The input is given in the following format.

$a$ $n$ $m$

The input line provides three integers: $a$ ($0 \leq a \leq 50$), $n$ ($2 \leq n \leq 10$) and the upper limit $m$ ($1000 \leq m \leq 10^8$).

Output

Output the number of integers that meet the above criteria.

Sample Input 1

16 2 1000

Sample Output 1

2

Two: $400 = (4 + 0 + 0 + 16)^2$ and $841 = (8 + 4 + 1 + 16)^2$

Sample Input 2

0 3 5000

Sample Output 2

3

Three: $1=1^3$, $512 = (5 + 1 + 2)^3$ and $4913 = (4 + 9 + 1 + 3)^3$.

Sample Input 3

2 3 100000

Sample Output 3

0

There is no such number $x$ in the range below $100,000$ such that its sum of decimal digits $y$ satisfies the relation $(y+2)^3 = x$.

Solution in C# (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;

class Root
{
    static T to<T>(string str)
    {
        return (T)Convert.ChangeType(str, typeof(T));
    }

    static string cin2str()
    {
        return System.Console.ReadLine().Trim();
    }

    static string[] cin2strs()
    {
        return cin2str().Split(' ');
    }

    static T[] cin2arr<T>()
    {
        return cin2strs().Select(line => to<T>(line)).ToArray();
    }

    static void Main(string[] args)
    {
        int[] arr = cin2arr<int>();
        var A     = arr[0];
        var N     = arr[1];
        var M     = arr[2];
        var nos = new List<ulong>();
        for (var i = 1;; ++i) {
            var ret_pow = (ulong)Math.Pow(i + A, N);
            if (ret_pow > (ulong)M) break;
            nos.Add(ret_pow);
        }
        var ret   = nos.AsParallel().Where(no => {
            var ints    = no.ToString().ToCharArray().Select(c => (int)char.GetNumericValue(c));
            var ret_pow = (ulong)Math.Pow(ints.Sum() + A, N);
            return no == ret_pow;
        });
        var count = ret.Count();
        Console.WriteLine("{0}", count);
    }
}