fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define NUM 600851475143
  6.  
  7. void sieve(int *table, int square);
  8.  
  9. int main(void) {
  10. int *table, square;
  11. long long i;
  12.  
  13. square = sqrt((double ) NUM);
  14. table = (int *) malloc( ( square + 1 ) * sizeof(int));
  15.  
  16. for(i = 0; i <= square; i++)
  17. table[i] = 1;
  18.  
  19. sieve(table, square);
  20.  
  21. for(i = square; i >= 2; i--) {
  22. if( !(NUM % i) && table[i] == 1) {
  23. printf("%lld\n", i);
  24. return 0;
  25. }
  26. }
  27.  
  28. printf("\n");
  29. return 0;
  30. }
  31.  
  32. void sieve(int *table, int square)
  33. {
  34. int i, j;
  35.  
  36. table[0] = table[1] = 0;
  37.  
  38. for(i = 2; i <= square; i++) {
  39. for(j = 2 * i; j <= square; j += i)
  40. table[j] = 0;
  41. }
  42. }
Success #stdin #stdout 0.12s 4704KB
stdin
Standard input is empty
stdout
6857