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;
}




 
   

转载于:https://www.cnblogs.com/pealicx/p/6115680.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值