Given two numbers n and r, the task is to find the value of nPr.
nPr represents n permutation r which is calculated as n!/(n-k)!. Permutation refers to the process of arranging all the members of a given set to form a sequence. The number of permutations on a set of n elements is given by n!, where “!” represents factorial.
nPr = n! / (n - r)!
5P2 = 20
Optimization for multiple queries of nPr
If there are multiple queries for nPr, we may precompute factorial values and use same for every call. This would avoid computation of same factorial values again and again.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- C program to calculate the value of nPr
- Program to calculate value of nCr
- Program to calculate the value of nCr Efficiently
- Java Program for Program to calculate area of a Tetrahedron
- Java Program to Calculate Sum of Two Byte Values Using Type Casting
- Calculate Stirling numbers which represents the number of ways to arrange r objects around n different circles
- Calculate MDAS Factorial of given number
- How to Convert a String value to Float value in Java with Examples
- How to Convert a String value to Byte value in Java with Examples
- How to Convert a String value to Short value in Java with Examples
- How to Convert a Byte value to String value in Java with Examples
- How to Convert a Double value to String value in Java with Examples
- How to Convert a Short value to String value in Java with Examples
- How to Convert a Float value to String value in Java with Examples
- Program to print ASCII Value of a character
- Program to find absolute value of a given number
- Java Program to Create an Object for Class and Assign Value in the Object Using Constructor
- Java Program to Print the ASCII Value
- Java Program for Program to find area of a circle
- Java Program for Program for array rotation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.