Write a program to Find Permutation
Given n and r, find the value of nPr.
( formula of npr=n!/(n-r)! )
Input Format
Take 2 input n and r as integer.
Constraints
1 <= n,r <= 10^4
Output Format
Print a integer as output.
Sample Input 0
5
2
Sample Output 0
20
Explanation 0
Take n = 5 and r = 2.
Output should be 20 by the formulae mentioned above.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int factorial(int n) {
int f;
for(f = 1; n > 1; n--){
f *= n;
}
return f;
}
static int npr(int n,int r) {
return factorial(n)/factorial(n-r);
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int r = sc.nextInt();
System.out.println(npr(n,r));
}
}