Pro.ID22111 TitleTeacher's Number Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22111 AC0 Submit0 Ratio- 时间&空间限制描述A teacher and his students play a number game. He divides his students into two groups and each group has k persons. At first, he asks each of the students in Group 1 to tell an integer, and the i-th (1 ≤ i ≤ k) student tells number Then, he appoints each of the students in Group 2 a positive integer, the i-th (1 ≤ i ≤ k) student appointed number mi and the greatest common divisor of every pair of numbers mi and mj (1 ≤ i < j ≤ k) is one. When each student has his own number, the teacher tells them, "Attention, everybody! I find an interesting thing. I have a nonnegative integer, and I find that when I subtract my number with bi, the difference happens to be divided exactly by mi. That happens with every pair of numbers bi and mi. Now can anyone of you tell me what my number is?" The students think for a long time and fail to solve the problem. Can you help them The answer may not be unique. To simplify the problem, you only need to find the smallest one. 输入The input text file contains several test cases. In each case, the first line is an integer k ( k < 30 ), the number of students in each group. The second line contains k integers, b1, b2, ..., bk the numbers chosen by the students in Group 1. The third line contains k positive integers, m1, m2, ..., mk, the numbers appointed to the students in Group 2. The file ends with k=0. 输出Description A teacher and his students play a number game. He divides his students into two groups and each group has k persons. At first, he asks each of the students in Group 1 to tell an integer, and the i-th (1 ≤ i ≤ k) student tells number Then, he appoints each of the students in Group 2 a positive integer, the i-th (1 ≤ i ≤ k) student appointed number mi and the greatest common divisor of every pair of numbers mi and mj (1 ≤ i < j ≤ k) is one. When each student has his own number, the teacher tells them, "Attention, everybody! I find an interesting thing. I have a nonnegative integer, and I find that when I subtract my number with bi, the difference happens to be divided exactly by mi. That happens with every pair of numbers bi and mi. Now can anyone of you tell me what my number is?" The students think for a long time and fail to solve the problem. Can you help them The answer may not be unique. To simplify the problem, you only need to find the smallest one. Input The input text file contains several test cases. In each case, the first line is an integer k ( k < 30 ), the number of students in each group. The second line contains k integers, b1, b2, ..., bk the numbers chosen by the students in Group 1. The third line contains k positive integers, m1, m2, ..., mk, the numbers appointed to the students in Group 2. The file ends with k=0. Output For each case, output one line containing the teacher's number. Sample Input 3 Sample Output 23 Source 样例输入3 样例输出23 作者 |