logo AlgoBeat OnlineJudge
登录 注册

#213490. [GCJ 2011 #1C] Perfect Harmony

内存限制:1024 MiB 时间限制:6000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Jeff is a part of the great Atlantean orchestra. Each player of the orchestra has already decided what sound will he play (for the sake of simplicity we assume each player plays only one sound). We say two sounds are in harmony if the frequency of any one of them divides the frequency of the other (that's a pretty restrictive idea of harmony, but the Atlanteans are known to be very conservative in music). Jeff knows that the notes played by other players are not necessarily in harmony with each other. He wants his own note to improve the symphony, so he wants to choose his note so that it is in harmony with the notes all the other players play.

Now, this sounds simple (as all the frequencies are positive integers, it would be enough for Jeff to play the note with frequency , or, from the other side, the Least Common Multiple of all the other notes), but unfortunately Jeff's instrument has only a limited range of notes available. Help Jeff find out if playing a note harmonious with all others is possible.

输入格式

The first line of the input gives the number of test cases, . test cases follow. Each test case is described by two lines. The first contains three numbers: , and , denoting the number of other players, the lowest and the highest note Jeff's instrument can play. The second line contains integers denoting the frequencies of notes played by the other players.

输出格式

For each test case, output one line containing "Case #: ", where is the case number (starting from ) and is either the string "NO" (if Jeff cannot play an appropriate note), or a possible frequency. If there are multiple frequencies Jeff could play, output the lowest one.

样例

样例输入 1

2
3 2 100
3 5 7
4 8 16
1 20 5 2

样例输出 1

Case #1: NO
Case #2: 10

数据范围与提示

Limits

  • .

Small dataset (8 Pts, Test set 1 - Visible)

  • .
  • .
  • All the frequencies are no larger than .
  • Time limit: 30 3 seconds.

Large dataset (35 Pts, Test set 2 - Hidden)

  • .
  • All the frequencies are no larger than
  • Time limit: 60 6 seconds.