Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. bool warunek(int x){
  5. if(x/10==0)return 1;
  6. while(x>10){
  7.     if(x%10<(x/10)%10) return 0;
  8.     x=x/10;
  9. }
  10. return 1;
  11. }
  12. void findPrimes(int a){
  13.     bool* tab = malloc(a*sizeof(bool));
  14.     tab[0]=0;
  15.     tab[1]=0;
  16.     for(int i=2;i<a;i++){
  17.         tab[i]=1;
  18.     }
  19. int j;
  20. for(int i=2;i*i<=a;i++){
  21.         if(tab[i]){
  22.             j=2*i;
  23.             while(j<a){
  24.                 tab[j]=0;
  25.                 j+=i;
  26.             }
  27.         }
  28.     }
  29.     for(int i=0;i<a;i++){
  30.         if(tab[i]){
  31.             if(!warunek(i))
  32.                 tab[i]=0;
  33.         }
  34.     }
  35.    for(int i=0;i<a;i++){
  36.         if(tab[i])printf("%d\n",i);
  37.     }
  38. }
  39. int main()
  40. { int a;
  41.     scanf("%d",&a);
  42.     findPrimes(a);
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement