UVa11970 - Lucky Numbers

Every person has its own numbers that he considers lucky. Usually the numbers are fixed like 3 or 7 and do not depend on anything. This lucky number model seems to be very primitive for John, so he decided to upgrade it for his own use. Maybe more complex model will bring more luck to him?

John has added a dependency for lucky numbers on specific integer N (for example N can be ordinal number of day in year or some other meaning). For each N John considers some number X lucky if and only if fraction X/√NX value is integer and greater than zero.

INPUT

The number of tests T (T ≤ 100) is given on the first line. T lines follow, each of them contains one integer N (1 ≤ N ≤ 109) described above.

OUTPUT

For each test case output a single line "Case T: S". Where T is the test case number (starting from 1) and S is increasing sequence of numbers considered lucky by John for specified N. Please refer to the sample output for clarity.

SAMPLE INPUT

3
16
109
33

SAMPLE OUTPUT

Case 1: 12 15
Case 2: 108
Case 3: 24 32
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
	public static final boolean DEBUG = false;
	public static final int N = 110;
	public StreamTokenizer tokenizer;
	public BufferedReader cin;
	public PrintWriter cout;
	public int n;
	public ArrayList<Integer> sqrt = new ArrayList<Integer>();
	
	public void init() 
	{
		try {
			if (DEBUG) {
				cin = new BufferedReader(new InputStreamReader(
						new FileInputStream("d:\\OJ\\uva_in.txt")));
			} else {
				cin = new BufferedReader(new InputStreamReader(System.in));
			}
			cout = new PrintWriter(new OutputStreamWriter(System.out));
			tokenizer = new StreamTokenizer(cin);
			
			for (int i = 1; i < 100000; i++) {
				long tmp = i;
				if (tmp * tmp <= 1000000000) sqrt.add(i);
				else break;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String next() 
	{
		try {
			tokenizer.nextToken();
			if (tokenizer.ttype == StreamTokenizer.TT_EOF) return null;
			else if (tokenizer.ttype == StreamTokenizer.TT_WORD) return tokenizer.sval; 
			else if (tokenizer.ttype == StreamTokenizer.TT_NUMBER) return String.valueOf((int)tokenizer.nval);
			else return null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public boolean input()
	{
		n = Integer.parseInt(next());
		return true;
	}	
	
	public void solve(int cas) 
	{
		ArrayList<Integer> ans = new ArrayList<Integer>();
		
		for (int i = 0, size = sqrt.size(); i < size; i++) {
			int tmp = sqrt.get(i);
			if (tmp * tmp >= n) break;
			
			int a = n - tmp * tmp;
			if (a % tmp == 0) ans.add(a);
		}
		
		Collections.sort(ans);
		cout.print("Case " + cas + ":");
		for (int i = 0, size = ans.size(); i < size; i++) {
			cout.print(" " + ans.get(i));
		}
		cout.println();
		cout.flush();
	}

	public static void main(String[] args) {
		Main solver = new Main();
		solver.init();
		
		int t = Integer.parseInt(solver.next());
		for (int i = 1; i <= t; i++) {
			solver.input();
			solver.solve(i);
		}
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值