Tag: 分解

C#中的元组和解包分配支持?

在Python中我可以写 def myMethod(): #some work to find the row and col return (row, col) row, col = myMethod() mylist[row][col] # do work on this element 但是在C#中,我发现自己在写作 int[] MyMethod() { // some work to find row and col return new int[] { row, col } } int[] coords = MyMethod(); mylist[coords[0]][coords[1]] //do work on this element […]

有效地找到数字的所有除数

所以我只想找到给定数字的所有除数(除了数字本身)。 目前,我有这个: public static List proper_divisors(int x) { List toreturn = new List(); toreturn.Add(1); int i = 0; int j=1; int z = 0; while (primes.ElementAt(i) < Math.Sqrt(x)) { if (x % primes.ElementAt(i) == 0) { toreturn.Add(primes.ElementAt(i)); toreturn.Add(x / primes.ElementAt(i)); j = 2; z = (int)Math.Pow(primes.ElementAt(i), 2); while (z < x) { if (x % […]