

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pollard’s Rho Algorithm for Prime Factorization in java
It is an algorithm to perform factorization on given integers. Following is the program implementing the Rho Algorithm for Prime Factorization.
Program
public class PollardsRho { int num = 65; public int gcd(int a, int b) { int gcd = 0; for(int i = 1; i <= a || i <= b; i++) { if( a%i == 0 && b%i == 0 ) { gcd = i; } } return gcd; } int g(int x) { return ((x*x)-1) % num; } public static void main(String args[]) { PollardsRho obj = new PollardsRho(); int x = 2, y = 2, d = 1; while(d==1) { x = obj.g(x); y = obj.g(obj.g(y)); d = obj.gcd((x - y), obj.num); } if (d == obj.num) { System.out.println("Cannot calculate GCD for this element"); } else { System.out.println("One of the divisors of given number is "+d); } } }
Output
One of the divisors of given number are 5
- Related Questions & Answers
- Prime Factorization using Sieve O(log n) for multiple queries in C++
- Dijkstra’s Algorithm for Adjacency List Representation
- Tarjan's Algorithm for Strongly Connected Components
- Stein’s Algorithm for finding GCD in C++
- C++ Program for Dijkstra’s shortest path algorithm?
- Minimum Factorization in C++
- Java program to check for prime and find next Prime in Java
- kasai’s Algorithm
- Manacher’s Algorithm
- Fleury’s Algorithm
- C / C++ Program for Dijkstra's shortest path algorithm
- Java Program for Reversal algorithm for array rotation
- Dijkstra's algorithm in Javascript
- Prim's algorithm in Javascript
- Kruskal's algorithm in Javascript
Advertisements