@Darklordx/

COPRIME

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
public class Main {
    public static void main(String[] args) {CoPrime();}
    
    public static ArrayList<Integer> CoPrime(){
        Stack<Integer> stack = new Stack<Integer>();
        ArrayList<Integer> res = new ArrayList<Integer>();
        //Initialization
        stack.push(2);
        stack.push(1);
        stack.push(3);
        stack.push(1);
        int m,n;
        while(!stack.isEmpty()){
            n = stack.pop();
            m = stack.pop();
            if(stop(m,n)){
                res.add(m);
                res.add(n);
                stack.push(2*m-n); stack.push(m);
                stack.push(2*m+n); stack.push(m);
                stack.push(m+2*n); stack.push(n);
            }
        }
        return(res);
    }

    public static boolean stop(int m, int n){ //Stopping function can be changed.
        return(m<=10&&n<=10);
    }
    

}