1370C - Number Game - CodeForces Solution


games math number theory *1400

Please click on ads to support us..

Python Code:

import sys
import random
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab,bc,cd : ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x : print(x)
prinT = lambda x : print(x)
f = lambda : sys.stdout.flush()
inv =lambda x:pow(x,mod-2,mod)
dx = [0,0,1,-1]
dy = [1,-1,0,0]
mod = 10**9 + 7
mod1 = 998244353

def pri(x) :
    if (x) :
        print("Ashishgup")
    else :
        print("FastestFinger")

for _ in range (ii()) :
    n = ii()

    if (n == 1) :
        pri(0)
        continue
    if (n%2 == 1 or n == 2) :
        pri(1)
        continue

    t = 0
    while (n%2 == 0) :
        t += 1
        n //= 2

    if (t>=2 and n == 1) :
        pri(0)
        continue

    if (t >= 2) :
        pri(1)
        continue

    p = 2
    fl = 0
    while (p*p <= n) :
        if (n%p == 0) :
            fl = 1
            break
        p += 1

    pri(fl)

C++ Code:

/*---------JAI HO GURUDEV---------*/ 

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f(i,n) for(ll i=0;i<n;i++)
#define fast cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
#define f1(i,n) for(ll i=n;i>=0;i--)
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define forr1(i,a,b) for(ll i=a;i>=a;i--)
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define sor(vec) sort(vec.begin(),vec.end())
#define asor(ar) sort(ar,ar+ar.size());
#define rsor(vec) sort(vec.rbegin(),vec.rend());
#define vl vector<ll>
#define yes cout << "YES"<< endl;
#define no cout << "NO"<< endl;
#define out(n) cout << n << endl;
#define num(n) ll n; cin >> n;
#define pb push_back
#define so(arr,n) sort(arr,arr+n) 
const ll MOD = 998244353;
#define mod 1000000007

// FERMAT'S LITTLE THEOREM
ll fastpow(ll a, ll b,ll Mod){
    ll res = 1;
    while(b > 0){
        if(b&1)
            res = (res * a) % Mod;
        a = (a * a) % Mod;
        b >>= 1;
    }
    return res;
}
vector<int>  SieveOfEratosthenes(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
 
    for (int p = 2; p * p <= n; p++) {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true) {
            // Update all multiples of p greater than or
            // equal to the square of it numbers which are
            // multiple of p and are less than p^2 are
            // already been marked.
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
 vector<int> v;
    // Print all prime numbers
    for (int p = 2; p <= n; p++)
        if (prime[p])
            v.pb(p);
        return v;
}
int position(ll x)
{
    int c=0;
    while(x!=0)
    {
        c++;
        x=x>>1;
    }
    return c;
}
bool compare(pair<ll,ll> a,pair<ll,ll> b)
{
    return (a.second-a.first)<(b.second-b.first);
}
pair<int,int> primeFactors(int n)
{
    // Print the number of 2s that divide n
    int rest=0,two=0;
    while (n % 2 == 0)
    {
        two++;
        n = n/2;
    }
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            rest++;
            n = n/i;
        }
    }
 
    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        rest++;
    pair<int,int> p={two,rest};
    return p;
}
void solve()
{
    ll n;
    cin>>n;
    if(n%2!=0)
    {
        if(n==1)
            cout<<"FastestFinger"<<endl;
        else
            cout<< "Ashishgup"<<endl;
    }
    else
    {
        pair<int,int> p=primeFactors(n);
       // cout<<p.first<<" "<<p.second<<endl;
        if(p.second==0)
        {
            if(p.first>1)
            {
                cout<<"FastestFinger"<<endl;
                
            }
            else
            {
              cout<< "Ashishgup"<<endl;  
            }
        }
        else
        {
            if(p.first>1)
            {
               cout<< "Ashishgup"<<endl;  
            }
            else
            {
                if(p.second>1)
                {
                    cout<< "Ashishgup"<<endl;
                }
                else
                {
                    cout<<"FastestFinger"<<endl;
                }
            }
        }
    }
}
int main()
{
     fast
           int t;
        cin>>t;
    for(int t1=1;t1<=t;t1++)
    {
        //body of the loop
   solve();  
  
    }
}

  


Comments

Submit
0 Comments
More Questions

1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments