- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Legendre’s Formula in javan
You can calculate the exponent of the largest power of a PrimeNumber that divides the factorial n! using Legendre's formula.
Program
import java.util.Scanner; public class LegendresFormula { static int Largestpower(int n, int p) { int ans = 0; while (n > 0) { n /= p; ans += n; } return ans; } public static void main (String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the n value :"); int n = sc.nextInt(); System.out.println("Enter the p value :"); int p = sc.nextInt(); int temp = n; int result = 0; while (temp > 0) { temp = temp / p; result = result + temp; } System.out.println("Largest power of "+p +" that divides "+ n+"! is :"+result); } }
Output
Enter the n value : 20 Enter the p value : 6 Largest power of 6 that divides 20! is :3
- Related Articles
- Legendre’s Conjecture: Concept, Algorithm, Implementation in C++
- Explain Heron's formula.
- What is Heron's formula?
- What is Boyle's law formula?
- Java Program to calculate the area of a triangle using Heron's Formula
- What do the symbols, H2, S and O4 mean in the formula H2SO4?
- Differentiate a Legendre series in Python
- Integrate a Legendre series in Python
- Work out the formula for sulphur dioxide. (Valencies : S = 4; O = 2)
- Regular Expression "S" Metacharacter in Java
- Kaufman's Adaptive Moving Average (KAMA) – Formula and how does it work?
- Format Seconds in s format in Java
- Add one Legendre series to another in Python
- Subtract one Legendre series from another in Python
- Multiply one Legendre series to another in Python

Advertisements