java - Factor table algorithm with complexity O(n·sqrt(n)) -
the following code prints table of factors of each number 0 n. can me rewrite following o(n²) time code has complexity o(n·sqrt(n)) time ?
i rewrote algorithm have o(n·log n) can't figure out complexity.
public static vector<vector<integer>> facttable(int n) { vector<vector<integer>> table = new vector<vector<integer>>(); (int = 1;i <= n; i++) { vector<integer> factors = new vector<integer>(); (int f = 1; f <= i; f++) { if ((i % f) == 0) factors.add(f); } table.add(factors); } return table; }
for each factor f of i, i/f factor of i.
Comments
Post a Comment