exhaustion
raw download clone
C
views 18
,
size 754 b
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>

bool isPrime(int k)
{
    int q = (int)sqrt((double)k);

    if (k == 1)
    {
        return false;
    }
    
    for (int i = 2;/*PRIMES[i] <= q &&*/ i <= q; i++)
    {
        if (k%i == 0)
        {
            return false;   
        }
    }
    return true;
}


int main() 
{ 
    int k = 4; 

    int count = 0;
    bool state = true;
    for (int i = 1; i <= 1e8; i++)
    {
        if (isPrime(i))
        {
            count++;   
        }
    }
    printf("\nthere are %d primes less than 100000000\n",count);
    printf("Method(exhaustion) : Use %d ms\n ",(int)clock());
    
  
    return 0; 
}
close fullscreen
Login or Register to edit or fork this paste. It's free.