1109 - False Ordering
Time Limit: 1 second(s) | Memory Limit: 32 MB |
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 | Output for Sample Input |
5 1 2 3 4 1000 | Case 1: 1 Case 2: 997 Case 3: 991 Case 4: 983 Case 5: 840 |
按照给定的规则将 i ( 1 ~ 1000)的因子排序,最后输出第n个数
#include<cstdio>
#include<algorithm>
using namespace std;
struct stu
{
int u,num;
}st[1005];
bool cmp(stu a,stu b)
{
if(a.u != b.u)
return a.u < b.u;
else
return a.num > b.num;
}
int main()
{
int t,k=0;
int i,j;
for(i = 1 ; i <= 1000 ; i++)
{
for(j = 1 ; i*j <= 1000 ; j++)
{
st[i*j].u++;
st[i*j].num = i*j;
}
}
sort(st,st+1001,cmp);
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
printf("Case %d: %d\n",++k,st[n].num);
}
}