-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeForOne.cpp
More file actions
47 lines (34 loc) · 810 Bytes
/
codeForOne.cpp
File metadata and controls
47 lines (34 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
string codeOneArray(unsigned long long int n);
string leftArr = "";
int main()
{
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
unsigned long long int n, l, r;
unsigned int ones = 0;
cin >> n >> l >> r;
string onesArray = codeOneArray(n).substr(l - 1, r - l + 1);
// ones = count(onesArray.begin(), onesArray.end(), '1');
// cout << ones << endl;
return 0;
}
string codeOneArray(unsigned long long int n)
{
if(n == 1)
return "1";
else
{
leftArr = codeOneArray(n / 2);
leftArr += (to_string(n % 2));
// leftArr.append(leftArr);
leftArr += leftArr;
return leftArr;
}
}