| Task: | Sum of ones |
| Sender: | aalto26em_007 |
| Submission time: | 2026-09-28 16:46:28 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.01 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.00 s | details |
| #7 | ACCEPTED | 0.00 s | details |
| #8 | ACCEPTED | 0.00 s | details |
| #9 | ACCEPTED | 0.00 s | details |
| #10 | ACCEPTED | 0.00 s | details |
| #11 | ACCEPTED | 0.00 s | details |
| #12 | ACCEPTED | 0.00 s | details |
| #13 | ACCEPTED | 0.00 s | details |
| #14 | ACCEPTED | 0.00 s | details |
| #15 | ACCEPTED | 0.00 s | details |
| #16 | ACCEPTED | 0.00 s | details |
| #17 | ACCEPTED | 0.00 s | details |
| #18 | ACCEPTED | 0.00 s | details |
| #19 | ACCEPTED | 0.00 s | details |
| #20 | ACCEPTED | 0.00 s | details |
| #21 | ACCEPTED | 0.00 s | details |
Code
#include<bits/stdc++.h>
//#include<unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
#define int long long
#define die(x) return cout << x << endl, 0
#define FI first
#define SE second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef map<int,int> mpi;
typedef set<int> sti;
typedef vector<pii> vii;
typedef map<pii,int> mpii;
typedef set<pii> stii;
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int power(int x, int y) { return (!y ? 1 : power(x, y / 2) * power(x, y / 2) * (y % 2 ? x : 1)); }
int to_int(string sconvert){stringstream geek(sconvert);int xconvert = 0; geek >> xconvert; return xconvert;}
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
const int MAXN=2e6+30,MAX_LOG=30,MOD=1e9+7,INF=1e9;
const double PI = acos(-1);
int mod(int x) { return (x % MOD + MOD) % MOD; }
int n, m, q;
// int parent[MAXN], sz[MAXN], population[MAXN];
// int eu[MAXN], ev[MAXN], ew[MAXN];
// int query_x[MAXN], query_y[MAXN], ans[MAXN], query_order[MAXN];
// void make_set(){
// for(int i=1;i<=n;i++)parent[i]=i;
// for(int i=1;i<=n;i++)sz[i]=1;
// }
// int find_set(int i){
// if(parent[i]==i)return i;
// else return parent[i]=find_set(parent[i]);
// }
// int union_set(int a,int b,int w){
// int x=find_set(a);
// int y=find_set(b);
// if(x==y){
// population[x]+=w;
// return 0;
// }
// if(sz[x]>sz[y])swap(x,y);
// parent[x]=y;
// sz[y]+=sz[x];
// population[y]+=population[x]+w;
// return 1;
// }
// bool compare_queries(int left,int right){
// return query_y[left]<query_y[right];
// }
int MAIN(){
cin>>n;
int answer=0;
for (int i=1; i<=n; i*=2){
int cycle = i * 2;
int complete_cycles = n /cycle;
int remainder = n%cycle;
answer += complete_cycles*i;
if(remainder >= i) answer += remainder - i + 1;
}
cout<<answer<<endl;
return 0;
}
int32_t main(){
IOS;
int t=1;
//cin>>t;
while(t--)MAIN();
return 0;
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 1 |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 2 |
| correct output |
|---|
| 2 |
| user output |
|---|
| 2 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 3 |
| correct output |
|---|
| 4 |
| user output |
|---|
| 4 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 4 |
| correct output |
|---|
| 5 |
| user output |
|---|
| 5 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 5 |
| correct output |
|---|
| 7 |
| user output |
|---|
| 7 |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 6 |
| correct output |
|---|
| 9 |
| user output |
|---|
| 9 |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 7 |
| correct output |
|---|
| 12 |
| user output |
|---|
| 12 |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 8 |
| correct output |
|---|
| 13 |
| user output |
|---|
| 13 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 9 |
| correct output |
|---|
| 15 |
| user output |
|---|
| 15 |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 10 |
| correct output |
|---|
| 17 |
| user output |
|---|
| 17 |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 303021765044187 |
| correct output |
|---|
| 7250167017244884 |
| user output |
|---|
| 7250167017244884 |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 390977392667778 |
| correct output |
|---|
| 9400236781929604 |
| user output |
|---|
| 9400236781929604 |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 670904313808571 |
| correct output |
|---|
| 16399391652009372 |
| user output |
|---|
| 16399391652009372 |
Test 14
Verdict: ACCEPTED
| input |
|---|
| 704275111916256 |
| correct output |
|---|
| 17252936460583174 |
| user output |
|---|
| 17252936460583174 |
Test 15
Verdict: ACCEPTED
| input |
|---|
| 799807335176164 |
| correct output |
|---|
| 19646099779305746 |
| user output |
|---|
| 19646099779305746 |
Test 16
Verdict: ACCEPTED
| input |
|---|
| 852012055430877 |
| correct output |
|---|
| 21005540865890493 |
| user output |
|---|
| 21005540865890493 |
Test 17
Verdict: ACCEPTED
| input |
|---|
| 901305628563213 |
| correct output |
|---|
| 22232965316761961 |
| user output |
|---|
| 22232965316761961 |
Test 18
Verdict: ACCEPTED
| input |
|---|
| 917427461591619 |
| correct output |
|---|
| 22650112032503064 |
| user output |
|---|
| 22650112032503064 |
Test 19
Verdict: ACCEPTED
| input |
|---|
| 981787468874797 |
| correct output |
|---|
| 24322274256024775 |
| user output |
|---|
| 24322274256024775 |
Test 20
Verdict: ACCEPTED
| input |
|---|
| 1000000000000000 |
| correct output |
|---|
| 24784747400675348 |
| user output |
|---|
| 24784747400675348 |
Test 21
Verdict: ACCEPTED
| input |
|---|
| 989898989898989 |
| correct output |
|---|
| 24531282955144033 |
| user output |
|---|
| 24531282955144033 |
