| Task: | Sum of ones |
| Sender: | aalto25g_002 |
| Submission time: | 2025-09-29 17:02:27 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | RUNTIME ERROR |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | RUNTIME ERROR | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | RUNTIME ERROR | 0.00 s | details |
| #5 | RUNTIME ERROR | 0.00 s | details |
| #6 | RUNTIME ERROR | 0.00 s | details |
| #7 | ACCEPTED | 0.00 s | details |
| #8 | RUNTIME ERROR | 0.00 s | details |
| #9 | RUNTIME ERROR | 0.00 s | details |
| #10 | RUNTIME ERROR | 0.00 s | details |
| #11 | RUNTIME ERROR | 0.00 s | details |
| #12 | RUNTIME ERROR | 0.00 s | details |
| #13 | RUNTIME ERROR | 0.00 s | details |
| #14 | RUNTIME ERROR | 0.00 s | details |
| #15 | RUNTIME ERROR | 0.00 s | details |
| #16 | RUNTIME ERROR | 0.00 s | details |
| #17 | RUNTIME ERROR | 0.00 s | details |
| #18 | RUNTIME ERROR | 0.00 s | details |
| #19 | RUNTIME ERROR | 0.00 s | details |
| #20 | RUNTIME ERROR | 0.00 s | details |
| #21 | RUNTIME ERROR | 0.00 s | details |
Code
#include <bits/stdc++.h>
void init_code() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
using namespace std;
void solve() {
int n;
cin >> n;
n += 1;
int res = 0;
bool flag = true;
int step = 2;
while (flag) {
int tmp = 0;
tmp += (n / step) * (step / 2);
tmp += (n % step) % (step / 2);
res += tmp;
if (tmp == 0) {
flag = false;
}
step *= 2;
}
cout << res << '\n';
/*
int ch = n;
int len = 0;
while (ch != 0) {
ch /= 2;
len++;
}
for (int i = n; i >= 0; --i) {
int x = i;
string res = "";
while (x != 0) {
if (x % 2 == 0) {
res += "0";
} else {
res += "1";
}
x /= 2;
}
while (res.length() != len) {
res += "0";
}
reverse(res.begin(), res.end());
cout << res << '\n';
}*/
}
signed main() {
init_code();
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 1 |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 2
Verdict: RUNTIME ERROR
| input |
|---|
| 2 |
| correct output |
|---|
| 2 |
| user output |
|---|
| (empty) |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 3 |
| correct output |
|---|
| 4 |
| user output |
|---|
| 4 |
Test 4
Verdict: RUNTIME ERROR
| input |
|---|
| 4 |
| correct output |
|---|
| 5 |
| user output |
|---|
| (empty) |
Test 5
Verdict: RUNTIME ERROR
| input |
|---|
| 5 |
| correct output |
|---|
| 7 |
| user output |
|---|
| (empty) |
Test 6
Verdict: RUNTIME ERROR
| input |
|---|
| 6 |
| correct output |
|---|
| 9 |
| user output |
|---|
| (empty) |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 7 |
| correct output |
|---|
| 12 |
| user output |
|---|
| 12 |
Test 8
Verdict: RUNTIME ERROR
| input |
|---|
| 8 |
| correct output |
|---|
| 13 |
| user output |
|---|
| (empty) |
Test 9
Verdict: RUNTIME ERROR
| input |
|---|
| 9 |
| correct output |
|---|
| 15 |
| user output |
|---|
| (empty) |
Test 10
Verdict: RUNTIME ERROR
| input |
|---|
| 10 |
| correct output |
|---|
| 17 |
| user output |
|---|
| (empty) |
Test 11
Verdict: RUNTIME ERROR
| input |
|---|
| 303021765044187 |
| correct output |
|---|
| 7250167017244884 |
| user output |
|---|
| (empty) |
Test 12
Verdict: RUNTIME ERROR
| input |
|---|
| 390977392667778 |
| correct output |
|---|
| 9400236781929604 |
| user output |
|---|
| (empty) |
Test 13
Verdict: RUNTIME ERROR
| input |
|---|
| 670904313808571 |
| correct output |
|---|
| 16399391652009372 |
| user output |
|---|
| (empty) |
Test 14
Verdict: RUNTIME ERROR
| input |
|---|
| 704275111916256 |
| correct output |
|---|
| 17252936460583174 |
| user output |
|---|
| (empty) |
Test 15
Verdict: RUNTIME ERROR
| input |
|---|
| 799807335176164 |
| correct output |
|---|
| 19646099779305746 |
| user output |
|---|
| (empty) |
Test 16
Verdict: RUNTIME ERROR
| input |
|---|
| 852012055430877 |
| correct output |
|---|
| 21005540865890493 |
| user output |
|---|
| (empty) |
Test 17
Verdict: RUNTIME ERROR
| input |
|---|
| 901305628563213 |
| correct output |
|---|
| 22232965316761961 |
| user output |
|---|
| (empty) |
Test 18
Verdict: RUNTIME ERROR
| input |
|---|
| 917427461591619 |
| correct output |
|---|
| 22650112032503064 |
| user output |
|---|
| (empty) |
Test 19
Verdict: RUNTIME ERROR
| input |
|---|
| 981787468874797 |
| correct output |
|---|
| 24322274256024775 |
| user output |
|---|
| (empty) |
Test 20
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000000000000 |
| correct output |
|---|
| 24784747400675348 |
| user output |
|---|
| (empty) |
Test 21
Verdict: RUNTIME ERROR
| input |
|---|
| 989898989898989 |
| correct output |
|---|
| 24531282955144033 |
| user output |
|---|
| (empty) |
