Description
We define b is a Divisor of a number a if a is divisible by b. So, the divisors of 12 are 1, 2, 3, 4, 6, 12. So, 12 has 6 divisors.
Now you have to order all the integers from 1 to 1000. x will come before y if
1) number of divisors of x is less than number of divisors of y
2) number of divisors of x is equal to number of divisors of y and x > y.
Input
Input starts with an integer T (≤ 1005), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 1000).
Output
For each case, print the case number and the nth number after ordering.
Sample Input
5
1
2
3
4
1000
Sample Output
Case 1: 1
Case 2: 997
Case 3: 991
Case 4: 983
Case 5: 840
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int f(int a)
{
int num=0,s;
for(int i=1;i*i<=a;i++)
{
if(a%i==0)
num++;
if(i*i==a)
s=1;
else
s=0;
}
return num*2-s;
}
struct node
{
int n,m;
}s[1001];
bool cmp(node a,node b)
{
if(a.m==b.m)
return a.n>b.n;
else
return a.m<b.m;
}
int main()
{
int t,n,k=1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
s[0].m=0;s[0].n=0;
for(int i=1;i<=1000;i++)
{
s[i].n=i;
s[i].m=f(i);
}
sort(s+1,s+1+1000,cmp);
printf("Case %d: ",k++);
printf("%d\n",s[n].n);
}
return 0;
}