using permutation and isprime functions