Created
March 22, 2024 19:27
-
-
Save SuryaPratapK/f218cd70cef3543f8b15e6fdf7cbbfc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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