CountNonDivisible【★★★★★】
1 /// <summary> 2 /// Solution 3 /// 100/100 4 /// </summary> 5 /// <param name="A"></param> 6 /// <returns></returns> 7 public static int[] solution(int[] A) 8 { 9 Dictionary<int, int> dic = new Dictionary<int, int>(); 10 int[] result = new int[A.Length]; 11 12 for (int i = 0; i < A.Length; i++) 13 { 14 if (!dic.ContainsKey(A[i])) 15 dic.Add(A[i], 1); 16 else 17 dic[A[i]]++; 18 } 19 20 for (int i = 0; i < A.Length; i++) 21 { 22 for (int j = 1; j * j <= A[i]; j++) 23 { 24 if (A[i] % j == 0) 25 { 26 result[i] += dic.ContainsKey(j) ? dic[j] : 0; 27 if (A[i] / j != j) 28 result[i] += dic.ContainsKey(A[i] / j) ? dic[A[i] / j] : 0; 29 } 30 } 31 result[i] = A.Length - result[i]; 32 } 33 34 return result; 35 }