fork download
  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. #define endl "\n"
  4. #define j1 ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  5. using namespace std;
  6. long long arr[55];
  7. bool ar[51];
  8.  
  9. long long check_prime(long long number){
  10. if(number ==2)
  11. return 1;
  12. if(number%2==0)//if(!(number&1)) it's time is much more better
  13. return 0;
  14. else{
  15. for(long long i=3;i*i<=number;i+=2){
  16. if(number%i==0)
  17. return 0;
  18. }
  19. return 1;
  20. }
  21.  
  22. }
  23. void fob_prim()
  24. {
  25. arr[0]=1;
  26. arr[1]=1;
  27. ar[0]=ar[1]=0;
  28. for(int i=2; i<=50; i++)
  29. {
  30. arr[i]=arr[i-1]+arr[i-2];
  31.  
  32. }
  33. for(int x=0; x<=50; x++)
  34. {
  35. ar[x]=check_prime(arr[x]);
  36. }
  37. }
  38. int main()
  39. {
  40. j1;
  41. int test,n;
  42. cin>>test;
  43. fob_prim();
  44. while(test--)
  45. {
  46. cin>>n;
  47. if(ar[n])
  48. {
  49. cout<<"prime"<<endl;
  50. }
  51. else
  52. {
  53. cout<<"not prime"<<endl;
  54. }
  55. }
  56.  
  57. }
Success #stdin #stdout 0.01s 5444KB
stdin
4
2
5
6
1
stdout
prime
not prime
prime
prime