BlueBear icon

sieveoferathosthenes

BlueBear | PRO | 09/30/13 03:02:33 PM UTC | 0 ⭐ | 476 👁️ | Never ⏰ | []
C |

1.26 KB

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <stdlib.h>
            
#define LIMIT 1300000
 
typedef struct prime
{
    int no;
    unsigned long long int number;
    struct prime *next;
}t_primes;
 
void sieveOfErathosthenes(unsigned int count)
{
    int *primes = NULL;
    t_primes *prim = NULL;
    t_primes *head = NULL;
    unsigned long long int i = 0;
    unsigned long long int j = 0;
    int z = 1;
 
    if(count >=1 && count <= 100000)
    {
        primes = (int *)malloc(sizeof(int)* LIMIT);
        prim = (t_primes *)malloc(sizeof(t_primes));
        head = prim;
 
        for (i=2 ; i < LIMIT; i++)
        {
            primes[i]=1;
        }
        
        for (i=2;i<LIMIT;i++)
        {
            if (primes[i])
            {
 
                prim->no = z++;
                prim->number = i;
                prim->next = (t_primes *)malloc(sizeof(t_primes));
                prim = prim->next;
 
                for (j=i;i*j<LIMIT;j++)
                {
                    primes[i*j]=0;
                }
            }
        }
        prim = head;
        while(prim->no != count)
        {
            prim = prim->next;
        }
 
        printf("\t%d\n", prim->number);
 
        /*for (i=2;i<LIMIT;i++)
        {
 
            if (primes[i] == 1)
            {
                if(z == count)
                {
                    printf("%d\n",i);
                    break;
                }
                z++;
            }
            
        }*/
    }
    else
    {
        exit(0);
    }
}
 
int main(void)
{
 
    int count = 1;
 
    while (scanf("%d", &count) > 0)
    {
        sieveOfErathosthenes(count);
    }
 
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  • Syutrsz icon
    03/31/26 10:26:44 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎