• Source
    1. #include <iostream>
    2. #include <math.h>
    3. #include <vector>
    4. using namespace std;
    5.  
    6. struct data
    7. {
    8. long front;
    9. long back;
    10. int i;
    11. data (long x, long y, int z)
    12. {
    13. front=x;
    14. back=y;
    15. i=z;
    16. }
    17. } typedef data;
    18.  
    19. vector <data> v;
    20. void init ()
    21. {
    22. long begin=1;
    23. long end=5;
    24. int i=0;
    25. int Index = pow (2, i);
    26. v.push_back(data (begin, end, Index));
    27. while (1)
    28. {
    29. if (end>1000000000) break;
    30. begin=end+1;
    31. i++;
    32. Index = pow (2, i);
    33. end=begin+Index*5-1;
    34. v.push_back(data (begin, end, Index));
    35. }
    36. }
    37.  
    38. int main ()
    39. {
    40. init ();
    41.  
    42. long N;
    43. cin>>N;
    44. int vt;
    45. for (int i=0; i<v.size(); i++)
    46. {
    47. if (N>=v[i].front && N<=v[i].back)
    48. {
    49. vt=i;
    50. break;
    51. }
    52. }
    53. long stt=N-v[vt].front+1;
    54. int Index=v[vt].i;
    55. if (stt>=0*Index+1 && stt<=1*Index)
    56. cout<<"1";
    57. else if (stt>=1*Index+1 && stt<=2*Index)
    58. cout<<"2";
    59. else if (stt>=2*Index+1 && stt<=3*Index)
    60. cout<<"3";
    61. else if (stt>=3*Index+1 && stt<=4*Index)
    62. cout<<"4";
    63. else if (stt>=4*Index+1 && stt<=5*Index)
    64. cout<<"5";
    65.  
    66. return 0;
    67. }