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 fib(ll n){
- ll n1 =0, n2 = 1, n3;
- if(n==1) return n1;
- if(n == 2) return n2;
- for(ll i =0; i<n-1; i++){
- n3 = n1+n2;
- n1 = n2;
- n2 = n3;
- }
- return 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;
- cout<<(is_prime(fib(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