False Ordering

http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=8086#problem/A

A - False Ordering

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

View Code
 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 struct pp 
 6 {
 7     int num,count;
 8 };
 9 pp a[1002];
10 
11 bool cmp(const pp &x,const pp &y)
12 {
13     if (x.count<y.count)
14     {
15         return true;
16     }
17     else
18         if (x.count>y.count) return
19              false;
20     else
21     {
22         if (x.num>y.num)
23     {
24         return true;
25     }
26         else return false;
27     }
28 }
29 int main()
30 {
31     int n,i,j;
32     for (i=1;i<1001;i++)
33     {
34         a[i].num=i;
35         for (j=1;j<=i;j++)
36         {
37             if (i%j==0)
38             {
39                 a[i].count++;                
40             }
41         }    
42     }
43     //cout<<a[1000].count<<endl;
44     sort(a,a+1001,cmp);
45     cin>>n;
46     for(i=1;i<=n;i++)
47     {
48         int m;
49         cin>>m;
50         cout<<"Case "<<i<<": "<<a[m].num<<endl;
51     }
52     return 0;
53 }
原文地址:https://www.cnblogs.com/wujianwei/p/2497273.html