Divisors is important when finding NOD, SOD, LCD or GCD etc. The sieve approach to the problem is following:

#include "divisiors.hpp"
#include <vector>
#include <iostream>
 
using namespace std;
 
vector<int>divisors[1000002];
 
void divisiors(int n){
    int i,j;
    for (i =1; i<=n; i++) {
        for (j =i; j<=n; j+=i) {
            divisors[j].push_back(i);
        }
    }
}

Now what is the time complexity of above program? . But why? shouldn’t this be . No. Even if there seems to be two loop, the complexity will be because,

For each there will be numbers of divisors. And this will give the harmonic sum:

In some problem the list of divisors are not needed. Instead they require NOD -> Number of Divisors or SOD -> Summation of Divisors.

The following formulas of Prime Factorial is pretty handy: Example: