Skip to content

Commit

Permalink
1175
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangshanmeta committed Nov 3, 2024
1 parent 3f9c696 commit 332ad1b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/1175.prime-arrangements.1279/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
private final int mod = 1000000007;
public int numPrimeArrangements(int n) {
int[] primes = new int[]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int prime = 0;
for(int i=0;i<primes.length;i++){
if(primes[i]>n){
break;
}
prime++;
}

return (int)(factorial(prime)*factorial(n-prime)%mod);
}

private long factorial(int n){
long result = 1;
while (n>0){
result = (result*n)%mod;
n--;
}
return result;
}

}

0 comments on commit 332ad1b

Please sign in to comment.