Java.Util Package Articles

Found 15 articles

Pollard’s Rho Algorithm for Prime Factorization in java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 346 Views

It is an algorithm to perform factorization on given integers. Following is the program implementing the Rho Algorithm for Prime Factorization.Programpublic class PollardsRho {    int num = 65;    public int gcd(int a, int b) {       int gcd = 0;       for(int i = 1; i

Read More

Euler’s Totient function for all numbers smaller than or equal to n in java

Chandu yadav
Chandu yadav
Updated on 25-Jun-2020 1K+ Views

Following is a program to get the result of Euler’s Totient function for all numbers smaller than or equal to n when n is given.Programimport java.util.Scanner; public class EulerTotient {    public static int gcd(int a,int b){       int i, hcf = 0;          for(i = 1; i

Read More

Euler’s criterion in java

Arjun Thakur
Arjun Thakur
Updated on 25-Jun-2020 584 Views

According to Euler’s criterion a square root of n under modulo p exists if and only if a number num exists such that num%p is equal to n%p.Programimport java.util.Scanner; public class EulersCriterion {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter n value :");             int n = sc.nextInt();       System.out.println("Enter p value :");       int p = sc.nextInt();       n = n % p;       int flag = 0;            for ...

Read More

Divisors of factorials of a number in java

Chandu yadav
Chandu yadav
Updated on 25-Jun-2020 247 Views

Following is a Java program to find the divisors of factorials of a number.Programimport java.util.Scanner; public class DivisorsOfFactorial {    public static long fact(int i) {       if(i

Read More

Legendre’s Formula in java\\n

George John
George John
Updated on 25-Jun-2020 315 Views

You can calculate the exponent of the largest power of a PrimeNumber that divides the factorial n! using Legendre's formula.Programimport 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 :");     ...

Read More

Binomial Coefficient in java

Ankith Reddy
Ankith Reddy
Updated on 25-Jun-2020 5K+ Views

Binomial coefficient (c(n, r) or nCr) is calculated using the formula n!/r!*(n-r)!. Following is the Java program find out the binomial coefficient of given integers.Programimport java.util.Scanner; public class BinomialCoefficient {    public static long fact(int i) {       if(i

Read More

Multiplicative order in java

Arjun Thakur
Arjun Thakur
Updated on 25-Jun-2020 188 Views

Following is a Java program which prints the multiplicative order of given numbers.import java.util.Scanner;Programpublic class MultiplicativeOrder {    public static int gcd(int num1, int num2) {       if (num2 != 0) {          return gcd(num2, num1 % num2);       } else {          return num1;       }    }    static int multiplicativeOrder(int num1, int num2) {       if (gcd(num1, num2) != 1) {          return -1;       }       int res = 1;       int p ...

Read More

Catalan numbers in java

Arjun Thakur
Arjun Thakur
Updated on 25-Jun-2020 842 Views

The nth Catalan number in terms of binomial coefficients is calculated by the formula(n + k )/k where k varies from 2 to n and n ≥ 0. i.e.Cn = (2n)!/((n+1)!n!)Programpublic class CatalanNumbers {    public static long fact(int i) {       if(i

Read More

k-th prime factor of a given number in java

George John
George John
Updated on 25-Jun-2020 424 Views

Following is the Java program which prints the kth prime factor of a number n, when k and n are given.Programimport java.util.Scanner; public class KthPrimeFactor {    public static void main(String args[]) {       int number, k, factor = 0;       Scanner sc = new Scanner(System.in);       System.out.println("Enter a number :");             number = sc.nextInt();       System.out.println("Enter the k value :");       k = sc.nextInt();       int temp = k-1;             for(int i = 2; i< number; ...

Read More

Find politeness of a number in java

Ankith Reddy
Ankith Reddy
Updated on 25-Jun-2020 277 Views

The numbers which can be expressed as the sum of positive consecutive integers are known as polite numbers.Ex: 5 = 2+3The number of ways a number can be expressed as the sum of positive integers will be the Politeness of that number.Ex: 9 = 4+5 || 2+3+4AlgorithmGet the prime factors of a number.Get the powers of prime factors greater than 2.Add 1 to all of them.Multiply them, subtract 1 from the result.Programimport java.util.Scanner; public class PolitenessOfANumber {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter a number");   ...

Read More
Showing 1–10 of 15 articles
« Prev 1 2 Next »
Advertisements