Ahmed_Negm

Untitled

Mar 8th, 2022
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<iomanip>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cstring>
  7. #include<vector>
  8.  
  9. #define ll long long
  10. #define sz(x) int(x.size())
  11. #define all(x) x.begin(),x.end()
  12. using namespace std;
  13.  
  14. void Fast_IO(){
  15.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  16.     #ifndef ONLINE_JUDGE
  17.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  18.     #endif
  19. }
  20.  
  21.  ll f[55];
  22.  void fib(ll n){
  23.     ll n1 =0, n2 = 1, n3;
  24.     ll j =0;
  25.    
  26.     for(ll i =1; i<n; i++){
  27.         if(i==1) f[j++] = n1;
  28.         if(i == 2) f[j++] = n2;
  29.         n3 = n1+n2;
  30.         f[j++] = n3;
  31.         n1 = n2;
  32.         n2 = n3;
  33.     }
  34.    
  35.  
  36.  }
  37.  bool is_prime(ll n){
  38.         if(n < 2 || (n % 2 == 0 && n != 2)) return false;
  39.         for(int i = 3; i <= sqrt(n); i += 2)
  40.             if(n % i == 0) return false;
  41.         return true;
  42.     }
  43.  
  44.  
  45.  
  46. void solve(){
  47. ll n; cin>>n;
  48. fib(n);
  49. cout<<(is_prime(f[n-1])? "prime\n" :"not prime\n");
  50.  
  51.  
  52. }
  53.  
  54. int main(){
  55.     Fast_IO();
  56. int t =1;
  57. cin>>t;
  58. while(t--){
  59. solve();
  60. }
  61. return 0;
  62. }  
Advertisement
Add Comment
Please, Sign In to add comment