Hi all,
I'm currently working on project euler problem 12 and my code is working, only problem is that it is to slow.
Quick explanation, It is a loop that goes from 1 to the value you gave the function and if the value divided by the Iterator is 0 it increments the counter.C++ Code:
int getDivisors(int n) { int c = 0; // the counter for (int i = 1; i < n; i++) { if (n % i == 0) c++; } return c; }
this works but gets extremely slow when large digits are involved (I did a profiling test and 99.9% of my programs running time is spent in this function)
Is there a way to calculate the number of divisors of a number instead of my brute force attempt ?






Reply With Quote