Sqrt(n)
Get all factors of N\n\n\nTime - O(sqrt(n))\nSpace - O(1)\n\n# C++\n    int sumOfSquares(vector& A) {\n        int res = 0, sz = size(A);\n        for(int i = 1
> Get all factors of `N`\n\n\nTime - `O(sqrt(n))`\nSpace - `O(1)`\n\n# C++\n    int sumOfSquares(vector<int>& A) {\n        int res = 0, sz = size(A);\n        for(int i = 1;i * i <= sz; ++i) {\n            if(sz % i == 0) {\n                res += A[i - 1] * A[i - 1];\n                int div = sz / i;\n                if(div != i) \n                    res += A[div - 1] * A[div - 1];\n            }\n        }\n        return res;\n    }\n\n# Java\n    public int sumOfSquares(int[] A) {\n        int res = 0, sz = A.length;\n        for(int i = 1;i * i <= sz; ++i) {\n            if(sz % i == 0) {\n                res += A[i - 1] * A[i - 1];\n                int div = sz / i;\n                if(div != i) \n                    res += A[div - 1] * A[div - 1];\n            }\n        }\n        return res;\n    }
[]