24h購物| | PChome| 登入
2012-06-22 19:20:42| 人氣1,018| 回應0 | 上一篇 | 下一篇

[UVA] 11970 - Lucky Numbers

推薦 0 收藏 0 轉貼0 訂閱站台

T  — Lucky Numbers

Time Limit: 1 sec
Memory Limit: 32 MB

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



#include <stdio.h>
#include <math.h>

int main() {
int t, test = 0, n, x;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
printf("Case %d:", ++test);
int i, sqr = sqrt(n);
for(i = sqr-1; i >= 1; i--) {
x = n-i*i;
if(x%i == 0)
printf(" %d", x);
}
puts("");
}
return 0;
}

台長: Morris
人氣(1,018) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 12416 - Excessive Space Remover
此分類上一篇:[UVA][BFS] 336 - A Node Too Far

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文