I need to find the number of divisors of an integer(n) for a problem in codechef. I have written the following program to compute the number of divisors. But the program is exceeding the time limit. Is there any way to optimize my approach to this problem?Can you suggest a faster algorithm?
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n,i=1,d=0;
while(i<=sqrt(n))
{
if(n%i==0)
{
d++;
if(i!=(n/i))
d++;
}
i++;
}
cout<<d;