# User talk:Enter your username

From Rosetta Code

## First perfect square in base N with N unique digits[edit]

The most time consuming ist evaluating the used digits.

static bool allInQS(BigInteger b) { BigInteger re; int c = ic; hs.Clear(); hs.UnionWith(o); while (b > bllim) { b = BigInteger.DivRem(b, Base, out re); hs.Add((byte)re); c += 1; if (c > hs.Count) return false; } return true; }

I think, using a combination of biginteger and machine size integers can improve this. First calculate the power of base, that fits into a machine integer and than use this maximised base for Bigint calculationes.

b = BigInteger.DivRem(b, BaseToPower, out re); for(i = 1; i<power, i++) // extract the count= power digits

If you need more speed, create for every base a seperat function. The compiler will use mul and shift instead of div, if the divisor is a constant.

// think of UInt64 as machine size of integer. static bool allInQSBase28(BigInteger b) { BigInteger re; int c = ic; hs.Clear(); hs.UnionWith(o); while (b > bllim) { b = BigInteger.DivRem(b, (28**13)6502111422497947648, out re); for(i = 1; i<13, i++){ div = re \ 28; mod = re - div*28; hs.Add((byte)mod);} .... } return true; }