Codeforces/Divisions.cpp
bool witness(long long a, long long n) {
    // check as in Miller Rabin Primality Test described
    long long u = n - 1;
    int t = 0;
    while (u % 2 == 0) {
        t++;
        u >>= 1;
    }
    long long next = modpow(a, u, n);
    if (next == 1) return false;
    long long last;
    for (int i = 0; i < t; ++i) {
        last = next;
        next = modpow(last, last, n);
        if (next == 1) {
            return last != n - 1;
        }
    }
    return next != 1;
}
// checks whether a is a witness that n is not prime, 1 < a < n
checks whether a is a witness that n is not prime, 1 < a < n
checks whether a is a witness that n is not prime 1 < a < n
bool witness(long long a, long long n) {
    long long u = n - 1;
    int t = 0;
    while (u % 2 == 0) {
        t++;
        u >>= 1;
    }
    long long next = modpow(a, u, n);
    if (next == 1) return false;
    long long last;
    for (int i = 0; i < t; ++i) {
        last = next;
        next = modpow(last, last, n);
        if (next == 1) {
            return last != n - 1;
        }
    }
    return next != 1;
}
bool witness ( long long a , long long n ) { long long u = n - 1 ; int t = 0 ; while ( u % 2 == 0 ) { t ++ ; u >>= 1 ; } long long next = modpow ( a , u , n ) ; if ( next == 1 ) return false ; long long last ; for ( int i = 0 ; i < t ; ++ i ) { last = next ; next = modpow ( last , last , n ) ; if ( next == 1 ) { return last != n - 1 ; } } return next != 1 ; }
checks whether a is a witness that n is not prime, 1 < a < n
checks whether a is a witness that n is not prime 1 < a < n
// check as in Miller Rabin Primality Test described