Skip to content

Instantly share code, notes, and snippets.

@SuryaPratapK
Created March 22, 2024 19:27
Show Gist options
  • Save SuryaPratapK/f218cd70cef3543f8b15e6fdf7cbbfc5 to your computer and use it in GitHub Desktop.
Save SuryaPratapK/f218cd70cef3543f8b15e6fdf7cbbfc5 to your computer and use it in GitHub Desktop.
class Solution {
long long permutation(int count,int MOD){
long long ans = 1;
for(int i=2;i<=count;++i)
ans = (ans*i)%MOD;
return ans;
}
public:
int numPrimeArrangements(int n) {
int MOD = 1e9+7;
int count = 0;
for(int i=2;i<=n;++i){
bool isPrime = true;
for(int j=2;j<=sqrt(i);++j){
if(i%j==0){
isPrime = false;
break;
}
}
if(isPrime==true)
count++;
}
return (permutation(count,MOD)*permutation(n-count,MOD))%MOD;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment