Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void sito(bool tab[])
  7. {
  8. int n=1000000;
  9. tab[0]=true;
  10. tab[1]=true;
  11. for(int i=2;i<=sqrt(n);i++)
  12. {
  13. if(tab[i]!=1)
  14. {
  15. int x=i;
  16. while(x*i<=n)
  17. {
  18. tab[x*i]=true;
  19. x++;
  20. }
  21. }
  22. }
  23. }
  24.  
  25. void fill(int *tab,bool arr[]){
  26. int j=0;
  27. for (int i = 2; i <= 1000000; ++i) {
  28. if(arr[i]==0){
  29. tab[j++]=i;
  30. }
  31. }
  32.  
  33. }
  34.  
  35. int isPrimeSum(int n,bool *tab1,int *tab2){
  36. if(n%2==1){
  37. if(tab1[n-2]==0){
  38. return 1;
  39. }
  40. else return 0;
  41. }
  42. else{
  43. for (int i = 0; i < n/2; ++i) {
  44. if(tab1[n-tab2[i]]==0){
  45. return 1;
  46. }
  47. else{
  48. continue;
  49. }
  50.  
  51. }
  52. return 0;
  53. }
  54. }
  55.  
  56. int n;
  57. bool tab1[1000000];
  58. int tab2[1000000];
  59.  
  60. int main() {
  61.  
  62. ios_base::sync_with_stdio(false);
  63. sito(tab1);
  64. fill(tab2,tab1);
  65.  
  66. while(cin>>n){
  67. if(n!=0){
  68. if(isPrimeSum(n,tab1,tab2)) cout<<"T"<<"\n";
  69. else cout<<"N"<<"\n";
  70. }
  71. else{}
  72. }
  73.  
  74.  
  75.  
  76. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement