Finding the prime factors of limit to calculate it 's  euler totient function
List < int > primes = new List < int > ( ) ; for ( int i = 2 ; i * i <= limit ; i ++ ) { if ( limit % i == 0 ) { while ( limit % i == 0 ) { limit /= i ; } primes . Add ( i ) ; } } if ( limit >= 2 ) { primes . Add ( limit ) ; }