fork(1) download
  1. #include <iostream>
  2. #include <array>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <stdlib.h>
  6. #include <cstdlib>
  7. #include <string>
  8. #include <vector>
  9. #include <iterator>
  10.  
  11. #define ne "\n"
  12. #define ll long long
  13. #define cinn copy(istream_iterator<int>(cin), istream_iterator <int>(), back_inserter(v))
  14. #define coutt copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "))
  15. #define ret return
  16.  
  17. int freq[1000];
  18. int freq2[1000];
  19.  
  20. using namespace std;
  21.  
  22.  
  23. int main()
  24. {
  25. //536870882
  26. //cout << 536870882.0000 / 268435455.0000 <<" ";
  27.  
  28. ll p; cin >> p;
  29. int ans=0;
  30. while (p > 0)
  31. {
  32. if (p%2!=0)
  33. {
  34. ans += 1;
  35. }
  36. p /= 2;
  37. }
  38. cout << ans<<ne;
  39.  
  40. ret 0;
  41. ll x;
  42. ll y=1;
  43. cin >> x;
  44. ll count = 1;
  45. ll maxx = 0;
  46. if (x==1)
  47. {
  48. cout << count<<ne; ret 0;
  49. }
  50. while (x > y)
  51. {
  52. if (y <= x)
  53. {
  54. maxx = y;
  55. cout << y << ne;
  56. }
  57.  
  58. y *= 2;
  59.  
  60. }
  61. if (maxx==x)
  62. {
  63. cout << count<<ne; ret 0;
  64. }
  65. else
  66. {
  67. count += (x - maxx);
  68. cout <<"count="<< count << ne;
  69. }
  70.  
  71.  
  72. }
Success #stdin #stdout 0s 5284KB
stdin
5
stdout
2