Ahmed_Negm

Untitled

Mar 8th, 2022
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 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 fib(ll n){
  22.     ll n1 =0, n2 = 1, n3;
  23.     if(n==1) return n1;
  24.     if(n == 2) return n2;
  25.     for(ll i =0; i<n-1; i++){
  26.         n3 = n1+n2;
  27.         n1 = n2;
  28.         n2 = n3;
  29.     }
  30.     return n3;
  31.  
  32.  }
  33.  bool is_prime(ll n){
  34.         if(n < 2 || (n % 2 == 0 && n != 2)) return false;
  35.         for(int i = 3; i <= sqrt(n); i += 2)
  36.             if(n % i == 0) return false;
  37.         return true;
  38.     }
  39.  
  40.  
  41.  
  42. void solve(){
  43. ll n; cin>>n;
  44. cout<<(is_prime(fib(n-1))? "prime\n" : "not prime\n");
  45.  
  46. }
  47.  
  48. int main(){
  49.     Fast_IO();
  50. int t =1;
  51. cin>>t;
  52. while(t--){
  53. solve();
  54. }
  55. return 0;
  56. }  
Advertisement
Add Comment
Please, Sign In to add comment