Welcome to ZOJ
Information
Problems
Runs
Statistics
Ranklist
Clarification
58 - The 7th Zhejiang University Programming Contests - 1006
Find the Sequences

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The sequence we discuss here is in the form a, a + b, a + 2b, a + 3b, ... where a is a non-negative integer and b is a positive integer. Your task is to find out all such sequences whose elements are of the form p3+q3 where p and q are non-negative integers.

Input:

The input consists of multiple test cases.

In each case, there're two integers n, m (3 <= n <= 10, 1 <= m <= 50). n, as mentioned above, is the number of terms in sequence, and m is the upper bound of p and q, which means 0 <= p, q <=m.

The input will be ended with "0 0" which should not be processed.

Output:

For each test case, output "Case #:" first. "#" is the number of the case, which starts from 1.

If no such sequence was found, simply output "NONE". Otherwise output the sequences in multiple lines, each line contains two integers a and b mentioned above. The sequence with smaller b comes first, if there's a tie, the one with smaller a comes first.

Separate two consecutive test cases with a blank line, but Do NOT output an extra blank line after the last one.

Sample Input:
4 10
9 1
0 0
Sample Output:
Case 1:
152 64
27 162

Case 2:
NONE

Submit    Status