I am currently using the following code but its very slow for large numbers
static int divisor(int number)
{
int i;
A solution if you know the smallest divisor is to apply the following formula:
largest_d = N - N % smallest_d
where N
is the number whose largest divisor you're looking for.
def largest_divisor(N, smallest_divisor):
return N - N % smallest_divisor
This code with a random big number (N = 94e15
) and a random big divisor (divisor = 21e3
) finished running the program in Python in 0.000740051269531 s
.
Hope this helps.