Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include<iomanip>
- #include<algorithm>
- #include<cstdlib>
- #include<cstring>
- #include<vector>
- #define ll long long
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- using namespace std;
- void Fast_IO(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- ll f[55];
- void fib(ll n){
- ll n1 =0, n2 = 1, n3;
- ll j =0;
- for(ll i =1; i<n; i++){
- if(i==1) f[j++] = n1;
- if(i == 2) f[j++] = n2;
- n3 = n1+n2;
- f[j++] = n3;
- n1 = n2;
- n2 = n3;
- }
- }
- bool is_prime(ll n){
- if(n < 2 || (n % 2 == 0 && n != 2)) return false;
- for(int i = 3; i <= sqrt(n); i += 2)
- if(n % i == 0) return false;
- return true;
- }
- void solve(){
- ll n; cin>>n;
- fib(n);
- cout<<(is_prime(f[n-1])? "prime\n" :"not prime\n");
- }
- int main(){
- Fast_IO();
- int t =1;
- cin>>t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment