DEV Community

Discussion on: Project Euler #3 - Largest Prime Factor

Collapse
 
khanhtc1202 profile image
Khanh Tran • Edited

C :))

int main(void)
{
  unsigned long long n = 600851475143ULL;
  unsigned long long i;

  for (i = 2ULL; i < n; i++) {
    while (n % i == 0) {
      n /= i;
    }
  }
  printf("%llu\n", n);

  return 0;
}
Collapse
 
ezeilosu profile image
Sunday Ezeilo

C is a powerful language. The same algorithm in Ruby shows to have time complexity issue. Good code, bro!