Happy 2006

Description

Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD) is 1. For instance, 1, 3, 5, 7, 9...are all relatively prime to 2006.

Now your job is easy: for the given integer m, find the K-th element which is relatively prime to m when these elements are sorted in ascending order.
Input

The input contains multiple test cases. For each test case, it contains two integers m (1 <= m <= 1000000), K (1 <= K <= 100000000).
Output

Output the K-th element in a single line.
Sample Input

2006 1
2006 2
2006 3
Sample Output

1
3
5

自己写了段Java代码 但不能完全解决您的问题 希望给您提供下思路:

 package lottery;

import java.util.Scanner;

public class example {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scan = new Scanner(System.in);
        System.out.print("Please Enter the group:");
        int group = scan.nextInt();
        int[][] Array = new int[group][2];
        System.out.println("Now,Please input the numbers:");
        for (int i = 0; i < group; i++) {
            Array[i][0] = scan.nextInt();
            Array[i][1] = scan.nextInt();
        }
        System.out.println("The Results:");
        for (int i = 0; i < group; i++) {
            System.out.println(Array[i][1] * 2 - 1);
        }
    }
}


![图片说明](https://img-ask.csdn.net/upload/201701/24/1485255989_828045.png)