-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f9c696
commit 332ad1b
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
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
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; | ||
} | ||
|
||
} |