mhdew

LightOJ 1109

Feb 4th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct info
  8. {
  9. int num;
  10. int div;
  11. };
  12.  
  13. bool cmp(struct info a, struct info b)
  14. {
  15. if(a.div==b.div)
  16. return (a.num>b.num);
  17.  
  18. return (a.div<b.div);
  19. }
  20.  
  21. int psqrt(int a)
  22. {
  23. double n;
  24.  
  25. n=sqrt(a);
  26.  
  27. if(n*n==a)
  28. return 1;
  29. }
  30.  
  31. int divisor(int a)
  32. {
  33. int i, n,count=0;
  34. n=sqrt(a);
  35.  
  36. for(i=1;i<=n;i++){
  37. if(a%i==0){
  38. count+=2;
  39. }
  40. }
  41. if(psqrt(a)==1)
  42. count--;
  43.  
  44. return count;
  45.  
  46. }
  47.  
  48. int main()
  49. {
  50. struct info a[10000];
  51. int i;
  52.  
  53. for(i=0;i<1000;i++){
  54. a[i].num=i+1;
  55. a[i].div=divisor(i+1);
  56. }
  57.  
  58. sort(a,a+1000,cmp);
  59.  
  60. // for(i=0;i<1000;i++)
  61. // printf("%4d=%d\n", a[i].num,a[i].div);
  62.  
  63. int n, j, m;
  64.  
  65. scanf("%d", &n);
  66. for(j=1;j<=n;j++){
  67. scanf("%d", &m);
  68.  
  69. m--;
  70.  
  71. printf("Case %d: %d\n", j, a[m].num);
  72. }
  73. return 0;
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment