FAQ Database Discussion Community

## solution of spoj NAJPWG. Gives TLE

c,algorithm,greatest-common-divisor
Link to the question is - spoj question I have tried solving the question by this approach - The number of pairs in N range = Number of pairs in N-1 range + some new pairs. But I don't know what else optimisation should be done here to avoid TLE....

## What is the reason behind calculating GCD in Pollard rho integer factorisation?

algorithm,math,greatest-common-divisor,number-theory,clrs
This is the pseudo code for calculating integer factorisation took from CLRS. But what is the point in calculating GCD involved in Line 8 and the need for doubling k when i == k in Line 13.? Help please....

## Using Euclid Algorithm to find GCF(GCD)

c++,algorithm,greatest-common-divisor
I am trying to write a function to find the gcd of 2 numbers, using Euclid's Algorithm which I found here. From the larger number, subtract the smaller number as many times as you can until you have a number that is smaller than the small number. (or without getting...

## While loop not executing

java,eclipse,debugging,while-loop,greatest-common-divisor
i am new to java and need help please. My while loop isn't working. It doesn't execute anything other than count. For this question I need to make fraction class that has mutator and accessory methods. Then I have to make the numerator and denominator to lowest form so i...

## How to calculate Least common multiple of {1, 2, 3, …, n}?

math,greatest-common-divisor,lcm
How to find LCM of {1, 2, ..., n} where 0 < n < 10001 in fastest possible way. The one way is to calculate n! / gcd (1,2,.....,n) but this can be slow as number of testcases are t < 501 and the output should be LCM ( n!...

## Explain how coprime check works

java,performance,greatest-common-divisor
Every time I use the Euclid method for checking if two numbers are co-prime. But there is one solution which has used this code to check for co-primeness, and the time taken by this was much faster than the Euclid method: (source) private static boolean isCoprime(long u, long v) {...