Advertisement
erfanul007

Timus 1086

Dec 26th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<stdio.h>
  2. long long int a[1000009],b[1000009];
  3.  
  4. void del(int i)
  5. {
  6. int j,k;
  7. for(j=2;i*j<1000000;j++){
  8. k=i*j;
  9. a[k]=0;
  10. }
  11. }
  12.  
  13. int main()
  14. {
  15. long long int i,j;
  16. a[1]=0;
  17. a[2]=-1;
  18. b[1]=2;
  19. for(i=3;i<1000000;i++){
  20. a[i]=-1;
  21. if(i%2==0)
  22. a[i]=0;
  23. }
  24. i=2;
  25. j=1;
  26. while(i<1000000){
  27. i++;
  28. if(a[i]==0)
  29. continue;
  30. j++;
  31. b[j]=i;
  32. del(i);
  33. }
  34. int n,x,k;
  35. scanf("%d",&n);
  36. for(k=1;k<=n;k++){
  37. scanf("%d",&x);
  38. printf("%d\n",b[x]);
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement