[关闭]
@Chilling 2016-08-19T18:02:37.000000Z 字数 994 阅读 962

swustoj-2394: JUST SORT


Description

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.

Input

there are many test cases.
Each case contains an integer n (1 ≤ n ≤ 100000).

Output

For each case, print the case number and the nth number after ordering.

Sample Input

1
2
3
4
1000

Sample Output

Case 1: 1
Case 2: 99991
Case 3: 99989
Case 4: 99971
Case 5: 88741

  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<algorithm>
  4. using namespace std;
  5. struct yz
  6. {
  7. int m;
  8. int n;
  9. }a[100005];
  10. int sum(int n)
  11. {
  12. if(n==1)return 1;
  13. int s=2,x,y,i;
  14. x=sqrt(n);
  15. for(i=2;i<=x;i++)
  16. {
  17. if(n%i==0)
  18. {
  19. y=n/i;
  20. if(y==i)
  21. s++;
  22. else
  23. s+=2;
  24. }
  25. }
  26. return s;
  27. }
  28. int cmp(yz a,yz b)
  29. {
  30. if(a.n==b.n)
  31. return a.m>b.m;
  32. return a.n<b.n;
  33. }
  34. int main()
  35. {
  36. int j,n,x=1;
  37. for(j=1;j<100001;j++)
  38. {
  39. a[j].m=j;
  40. a[j].n=sum(j);
  41. }
  42. sort(a+1,a+100001,cmp);
  43. while(scanf("%d",&n)!=EOF)
  44. {
  45. printf("Case %d: %d\n",x,a[n].m);
  46. x++;
  47. }
  48. return 0;
  49. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注