[UVA] 11970 - Lucky Numbers
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/√N−X 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;
}