Task: | Sum of ones |
Sender: | aalto2024e_005 |
Submission time: | 2024-09-30 16:38:12 +0300 |
Language: | C++ (C++20) |
Status: | COMPILE ERROR |
Compiler report
cc1plus: error: '::main' must return 'int'
Code
#include <iostream> #include <vector> #include <string> #include <math.h> using namespace std; long long largest_power(long long n){ long long x = 0; while ((1 << x) <= n) ++x; return x-1; } long long count(long long n){ if (n <= 1) return n; long long x = largest_power(n); return (x * pow(2, (x-1)) + (n- pow(2, x) +1) + count(n - pow(2, x))); } long long main() { long long n; cin >> n; cout << count(n) << endl; }