22111_Teacher'sNumber

2022-5-16 18:21| 发布者: Hocassian| 查看: 26| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506117707500-Problem List-采集的数据-后羿采集器.html

Pro.ID

22111

Title

Teacher's Number

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22111

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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 ≤ ik) student tells number Then, he appoints each of the students in Group 2 a positive integer, the i-th (1 ≤ ik) student appointed number mi and the greatest common divisor of every pair of numbers mi and mj (1 ≤ i < jk) 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 ≤ ik) student tells number Then, he appoints each of the students in Group 2 a positive integer, the i-th (1 ≤ ik) student appointed number mi and the greatest common divisor of every pair of numbers mi and mj (1 ≤ i < jk) 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
    1 2 3
    2 3 5
    0

    Sample Output

    23

    Source

    样例输入

    3
    1 2 3
    2 3 5
    0

    样例输出

    23

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部