【leetcode】质数排列

bool isprime(int count)
{
    if (count ==1) return false;
    for (int j=2; j<=sqrt(count); j++) 
    {
        if(count % j == 0) return false; 
    }
    return true;
}
int numPrimeArrangements(int n){
    int i,pCount=0,cCount=0;
    long long result=1;
    for (i=1; i<=n; i++)
    {
        (isprime(i))? pCount++: cCount++;
    }
    while(pCount || cCount)
    {
        if (pCount) result = (result * pCount--) % 1000000007;
        if (cCount) result = (result * cCount--) % 1000000007;
    }
    return result;
}
原文地址:https://www.cnblogs.com/ganxiang/p/13650967.html