Leetcode 2778 - Sum of Squares of Special Elements

題目

Problem#

給你一個 1-index 的陣列 nums 長度 $n$,對於 $nums[i]$ 滿足 n % i == 0 為特殊數字
回傳所有特殊數字的平方和

測資限制#

  • $1 \le n, val \le 50$

想法#

照題目所述的規則掃過一次,累計特殊數字即可

  • 時間複雜度: $\mathcal{O}(n)$
  • 空間複雜度: $\mathcal{O}(1)$

AC Code#