kostantinaras

prime

Mar 20th, 2012
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3. unsigned int n_from, n_to,n[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101},prime,riza,kr;
  4. int main(void)
  5. {
  6. //--------------------------------------------------------
  7. //---------------------------------------------------------
  8. FILE * in = fopen ("function.in", "r");
  9.    FILE * out = fopen ("function.out", "w");
  10.    fscanf (in , "%d %d", &n_from, &n_to);
  11.  //--------------------------------------------------------
  12. //---------------------------------------------------------
  13. if (n_from > n_to)
  14. {
  15.   kr=n_from;
  16.   n_from=n_to;
  17.   n_to=kr;
  18.  
  19. }  
  20.  
  21. n_from++;
  22. //--------------------------------
  23. if (n_from == 2)
  24.    n_from++;
  25. while (n_from < n_to)
  26. {
  27.     riza=sqrtf(n_from);
  28.    
  29.       if(prime==1)
  30.       goto kalo_loop;
  31.      
  32.  //--------------------------------------------------------------------------------
  33.    
  34.     kr=0;
  35.     for (n[kr]; n[kr] <= riza; kr++)   // check if prime
  36.           {
  37.            if ((n_from % n[kr]) == 0)
  38.              {n_from--;
  39.               goto loop;
  40.               }
  41.            
  42.             }
  43.        
  44.     //--------print----------------------------------------
  45.         fprintf(out,"%d", n_from);
  46.          
  47.          prime=1;
  48.          goto loop;      
  49.            
  50. //-------------------------------------------------------------------------------------------
  51. //-----------------------------------------------------------------------------------------  
  52.  kalo_loop:
  53.        
  54.       kr=0;
  55.     for (n[kr]; n[kr] <= riza; kr++)   // check if prime
  56.           {
  57.            if ((n_from % n[kr]) == 0)
  58.              goto loop;
  59.            
  60.             }
  61.        
  62. //----------print---------------
  63. //----------print----------------      
  64.         fprintf(out," %d", n_from);
  65.        
  66.  loop:
  67. n_from+=2;
  68.     }
  69.  if (prime == 1)
  70.  fprintf(out,"\n");
  71.    end:
  72.    fclose(in); fclose(out);
  73.    return 0;
  74.    }
RAW Paste Data