Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

two programs are added

  • Loading branch information...
commit d647bc3cd313b571d1955284a266c8bd318506ed 1 parent 7a7b00f
@nallachaitu authored
Showing with 88 additions and 0 deletions.
  1. +47 −0 largestPrimeFactor.java
  2. +41 −0 pythTriplet.java
View
47 largestPrimeFactor.java
@@ -0,0 +1,47 @@
+//The program computes largest primeFactor for any given number
+
+public class largestPrimeFactor
+{
+ public boolean isPrime(long num)
+ {
+ long i = 2;
+ if(num == 1 || num == 0)
+ return false;
+ for(;i<num/2;i++)
+ {
+ if(num % i == 0)
+ return false;
+ }
+
+ return true;
+ }
+ public long getLargestPrime(long num)
+ {
+ int i=2;
+ long currPrime = -1;
+ long dividend = num;
+ while(i <= num && dividend > 1)
+ {
+ if(dividend % i == 0)
+ {
+ dividend = dividend / i ;
+ if(isPrime(i))
+ currPrime = i;
+ }
+ i++;
+ }
+ return currPrime;
+ }
+ public static void main(String[] args)
+ {
+ long number = 600851475143L;
+ largestPrimeFactor test = new largestPrimeFactor();
+ long result = test.getLargestPrime(number);
+ System.out.println("The largest Prime Factor : " + result);
+ }
+
+
+
+
+
+}
View
41 pythTriplet.java
@@ -0,0 +1,41 @@
+//the program computes the product of the values of the Pythogorean triplet whose sum is equal to the limit like 1000
+
+public class pythTriplet
+{
+ public int productOfTriplet(int limit)
+ {
+ int sumOfSquares = 0;
+ for(int i=1;i<limit-1;i++)
+ {
+ for(int j=1;j<limit-1;j++)
+ {
+ if(i+j>limit-2 )
+ break;
+ for(int k=1;k<limit-1;k++)
+ {
+ if(i+j+k == limit)
+ {
+ sumOfSquares = i*i + j*j;
+ if(k*k == sumOfSquares)
+ return i*j*k;
+ }
+ }
+
+
+ }
+
+
+ }
+
+ return -1;
+
+ }
+public static void main(String args[])
+{
+ pythTriplet testClass = new pythTriplet();
+ int result = testClass.productOfTriplet(1000);
+ System.out.println(result);
+}
+
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.