Task: | Sum of ones |
Sender: | aalto2024e_007 |
Submission time: | 2024-09-30 17:49:37 +0300 |
Language: | C++ (C++11) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'long long int func(long long int)': input/code.cpp:26:12: error: invalid conversion from 'long long int (*)(long long int)' to 'long long int' [-fpermissive] 26 | ll m = getnextBit | ^~~~~~~~~~ | | | long long int (*)(long long int) input/code.cpp:3:12: error: expected ',' or ';' before 'long' 3 | #define ll long long | ^~~~ input/code.cpp:27:5: note: in expansion of macro 'll' 27 | ll m = getmostBit(n, m); | ^~
Code
#include<vector> #include<iostream> #define ll long long using namespace std; ll getnextBit(ll n){ ll m = 0; while (n > 1) { n = n >> 1; m+=1; } return m; } ll getmostBit(ll n, ll m){ ll tmp = 1 << m; while (n < tmp) { tmp = tmp >> 1; --m; } return m; } ll func(ll n){ if (n == 0) return 0; ll m = getnextBit ll m = getmostBit(n, m); if (n == (1LL << (m + 1)) - 1) return (m + 1) * (1 << m); n = n - (1LL << m); return (n + 1) + func(n) + m * (1LL << (m - 1)); } int main(){ int n; cin >> n; cout<<func(n)<<endl; }