Number of factors of Numbers in range [1,1e6]

I was doing Atcoder Beginner Contest yesterday.For problem C i counted the number of factors of n-c for all valid c. In order to precompute number of factors for numbers in range [1,1e6]. I tweaked seive like this:
vi := vector

vi factorize (vi v){
	v[0]=0; 
	v[1]=1;
	for(int i=2;i<N;i++)
		v[i]=1;       //counting 1 as a factor for all numbers>=1
	for(int i=2;i<N/2;i++)
		for(int j=i;j<N;j+=i){
			v[j]+=1;    
		}
	return v;
}

But it may accidentally have worked for first two cases but didn’t work for n=1e6(The last sample case)
please help me find where did it went wrong?

Thank You in advance

Update : I got my mistake

int f[1000001];
 
signed main(){
    int n;
    cin>>n;
    
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i){
            f[j]++;
        }
    }
    
    int cnt=0;
    for(int ab=1;ab<=n;ab++){
        int c=n-ab;
        if(c<=0)continue;
        cnt+=f[ab];
        
    }
    cout<<cnt;
}

Compare it with this one.

1 Like

Thank You for replying
I got my mistake