@@ -0,0 +1,1706 @@
+import java.util.Scanner;%0A%0Apublic class Main %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        Scanner sc = new Scanner(System.in);%0A%0A        while (true) %7B%0A%0A            int a1 = sc.nextInt();%0A            int m1 = sc.nextInt();%0A            int a2 = sc.nextInt();%0A            int m2 = sc.nextInt();%0A            int a3 = sc.nextInt();%0A            int m3 = sc.nextInt();%0A%0A            if (a1 == 0 && a2 == 0 && a3 == 0 && m1 == 0 && m2 == 0 && m3 == 0) %7B%0A                break;%0A            %7D%0A%0A            long x = 1;%0A            long countX = 0;%0A%0A            long y = 1;%0A            long countY = 0;%0A%0A            long z = 1;%0A            long countZ = 0;%0A%0A            while (true) %7B%0A%0A                x = a1 * x %25 m1;%0A                countX++;%0A%0A                if (x == 1) %7B%0A                    break;%0A                %7D%0A%0A            %7D%0A%0A            while (true) %7B%0A%0A                y = a2 * y %25 m2;%0A                countY++;%0A%0A                if (y == 1) %7B%0A                    break;%0A                %7D%0A%0A            %7D%0A%0A            while (true) %7B%0A%0A                z = a3 * z %25 m3;%0A                countZ++;%0A%0A                if (z == 1) %7B%0A                    break;%0A                %7D%0A%0A            %7D%0A%0A            long lcm1 = lcm(countX, countY);%0A            long lcm2 = lcm(countZ, lcm1);%0A%0A            System.out.println(lcm2);%0A%0A        %7D%0A%0A    %7D%0A%0A    private static long gcd(long x, long y) %7B%0A%0A        if (x %3C y) %7B%0A%0A            long tmp = x;%0A            x = y;%0A            y = tmp;%0A%0A        %7D%0A%0A        while (y != 0) %7B%0A%0A            long r = x %25 y;%0A            x = y;%0A            y = r;%0A%0A        %7D%0A%0A        return x;%0A%0A    %7D%0A%0A    private static long lcm(long x, long y) %7B%0A        return x * y / gcd(x, y);%0A    %7D%0A%0A%7D%0A

Create : 0114