JUST SORT

We define  B  is a Divisor of one 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 in total.
Now you have to order all the integers from  1  to  100000 by the following rules: 
X  will come before  Y  if
(1)  the number of divisors of  X  is less than the number of divisors of Y
(2)  the number of divisors of  X  is equal to the number of divisors of  Y  and  X > Y.
there are many test cases.
Each case contains an integer n (1 ≤ n ≤ 100000).
For each case, print the case number and the nth number after ordering.
1
2
3
4
1000
Case 1: 1
Case 2: 99991
Case 3: 99989
Case 4: 99971
Case 5: 88741
<pre name="code" class="cpp">#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
priority_queue<int>que[129];
const int n=100000;
int a[n+1],b[n+1];
void star(){
    fill(a,a+n+1,0);
    fill(b,b+n+1,0);
    for(int i=1;i<=n;i++){
        for(int j=1;i*j<=n;j++){
            a[i*j]++;
        }
    }
    for(int i=0;i<=n;i++){
        que[a[i]].push(i);
    }
    for(int k=1,i=1;i<=128;i++){
        while(!que[i].empty()){
            b[k++]=que[i].top();
            que[i].pop();
        }
    }
}
int main ()
{
    star();
    int k=1,t;
    while(~scanf("%d",&t))
        printf("Case %d: %d\n",k++,b[t]);
    return 0;
}





posted @ 2016-04-03 14:03  _Mickey  阅读(130)  评论(0编辑  收藏  举报