I am new to number theory, I have to find the number of divisors up to $10^9$, but i dont know how to do it efficiently and store it in an array in 'c'. I am using sieve algo to find the number of divisors, here is what I am doing
#include<stdio.h>
#define N 100000
int div[N+1];
void divisors() {
int i,len,j;
for(i=2;i<=N;i++) {
for(j=i;j<N;j+=i)
div[j]++;
}
}
int main(){
int i;
divisors();
for(i=1;i<N;i++) printf("%d\n",div[i]+1);
return 0;
}
Thank You
unsigned long long, so you'd have to trade some speed for space. – Daniel Fischer Sep 08 '13 at 20:48