Code #3


SUBMITTED BY: Guest

DATE: Nov. 30, 2014, 7:26 p.m.

FORMAT: C++

SIZE: 1.1 kB

HITS: 1198

  1. #include <iostream>
  2. // SUMA PIERWSZYCH
  3. using namespace std;
  4. bool tab[1000000];
  5. void s(){
  6. for (int i=2; i*i<=1000000; i++)
  7. {
  8. if(!tab[i])
  9. for (int j = i*i ; j<=1000000; j+=i)
  10. tab[j] = 1;
  11. }
  12. }
  13. int main()
  14. {
  15. s();
  16. int n;
  17. bool mam;
  18. while(cin>>n)
  19. {
  20. if(n!=0)
  21. {
  22. if(n%2==0)
  23. {
  24. mam = false;
  25. for(int i = 3; i*i <= n; i+=2 )
  26. {
  27. if(n-tab[i]==1)
  28. {
  29. mam = true;
  30. break;
  31. }
  32. }
  33. if(mam) cout<<"N"<<endl;
  34. else cout<<"T"<<endl;
  35. }
  36. else
  37. {
  38. if(tab[n-2]==1) cout<<"N"<<endl;
  39. else cout<<"T"<<endl;
  40. }
  41. }
  42. else break;
  43. }
  44. return 0;
  45. }

comments powered by Disqus