Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.math.*;
- public class Main
- {
- public static void main(String[] args) {
- long[][] lst;
- lst = new long[][] { {76, 380}, {52, 260}, {48, 144}, {40, 200}, {48, 144}, {64, 192}, {64, 256}, {78, 390}, {50, 100} };
- System.out.println(convertFrac(lst));
- }
- public static String convertFrac(long[][] lst) {
- // your code
- BigInteger[] num = new BigInteger[lst.length];
- BigInteger[] den = new BigInteger[lst.length];
- BigInteger common = new BigInteger("1");
- /*long[] num = new long[lst.length];
- long[] den = new long[lst.length];
- long common = 1;*/
- for (int i = 0; i < lst.length; i++){
- /*num[i] = lst[i][0];
- den[i] = lst[i][1];
- common *= lst[i][1];*/
- num[i] = new BigInteger(String.valueOf(lst[i][0]));
- den[i] = new BigInteger(String.valueOf(lst[i][1]));
- common = common.multiply(new BigInteger(String.valueOf(lst[i][1])));
- //System.out.println(num[i] + " " + den[i] + " " + common);
- }
- //System.out.println(common);
- for (int i = 0; i < num.length; i++){
- BigInteger factor = common.divide(den[i]);
- num[i] = num[i].multiply(factor);
- //System.out.println(num[i]);
- }
- BigInteger[] copy = Arrays.copyOf(num, num.length);
- Arrays.sort(copy);
- for (BigInteger b : copy){
- System.out.println(b);
- }
- /*for (long i = copy[0]; i > 0; i--) {
- final long I = i;
- if ((Arrays.stream(num).filter(l -> l%I == 0).count() == num.length) && common%i == 0){
- for (int j = 0; j < num.length; j++){
- num[j] /= i;
- }
- common /= i;
- }
- }*/
- StringBuilder sb = new StringBuilder("");
- for (BigInteger l : num) {
- sb.append("(");
- sb.append(l);
- sb.append(",");
- sb.append(common);
- sb.append(")");
- }
- return sb.toString();
- }
- }
Add Comment
Please, Sign In to add comment