algorithm - How to solve some algebraic expressions and find the GCD of a number and one obtained from evaluating the algebra in Java -
i'm writing java program find gcd (greatest common divisor) of number n. program should evaluate algebraic expression. lemme explain further; 1. calculate √(n) 2. divide result of (1) above 18. 3. compute ceiling function of step(2) above , call f. in other words, f = ceiling function of [√(n) divided 18]. 4. set following 3 algebraic expressions in x , execute them sequentially (a) (c):
a) h1(x) = (n -1-18x ), x take values 0 f. each x, compute gcd of h1(x) , n. let’s call gcd, d. is, d= gcd (n, h1(x)) or ( n, h1(x)). if d =1, increase x 1 , continue until d > 1 or come x = f. if d > 1, have found 1 nontrivial divisor of n. call q. other divisor of n value of h1(x) divided q plus 1. let’s call p. therefore, p = ( +1). state divisors of n p , q. prompt n entered or ask if user wants enter n tested- y/n option.
but if not find gcd > 1 h1(x) between x = 0 , x = f, move (b) below:
b) h2(x) = (n -11-18x ), x range 0 f. each x, compute gcd of h2(x) , n. let’s call gcd, d. is, d= gcd(n, h2(x)) or ( n, h2(x)). if d =1, increase x 1 , continue until d > 1 or come x = f.
if d > 1, have found 1 nontrivial divisor of n. call q. other divisor of n value of h2(x) divided q. let’s call p.
therefore, p = ( +1). state divisors of n p , q. prompt n entered or ask if user wants enter n tested- y/n option.
but if not find gcd > 1 h2(x) between x = 0 , x = f, move (c) below:
c) h4(x) = (n -13-18x ), x range 0 f. each x, compute gcd of h4(x) , n. let’s call gcd, d. if d =1, increase x 1 , continue until d > 1 or come x = f. if d > 1, have found 1 nontrivial divisor of n. call q. other divisor of n value of h4(x) divided q. let’s call p.
therefore, p = ( +1).
then state divisors of n p , q.
see i've done far;
public static void main(string[] args) { int num; double sqrtnum; double dividedsqrtnum; double f; int x = 0; float a; int d; float p; int q; scanner input = new scanner(system.in); system.out.println("enter number 'n'"); num = input.nextint(); if( (num % 3) != 0){ system.out.println( "the number entered semi-prime"); sqrtnum = math.sqrt(num); dividedsqrtnum = sqrtnum / 18; f = math.ceil(dividedsqrtnum) ; system.out.println("the value of f " + f); // algebraic expressions (x=0; x <= f; x++){ while (d == 1 || x ==f){ = (num - 1 - 18 * x); d = findgcd(num,a); if ( d == 1){ x = x++; } else{ q = d; p = (a / q + 1); system.out.println("the divisors of "+ num +" "+ p +" , " + q +" want test number? y or n " ); } } } } else{ system.out.println("the number not semi-prime"); } }
private static int findgcd(float num,float a) { //base case return findgcd(a, num%a); } } help me guys, i'm stuck.
Comments
Post a Comment