-
Notifications
You must be signed in to change notification settings - Fork 0
/
mynumbersys.cpp
59 lines (51 loc) · 976 Bytes
/
mynumbersys.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <vector>
using namespace std;
void print(vector <int> v){
for(int i=0; i<v.size(); i++)
cout<<v[i];
cout<<endl;
}
int numberise(vector <int> v){
int k=0;
for(int i=v.size()-1; i>=0; i--){
k += v[i];
k *= 10;
}
return k/10;
}
int generate(vector <int> &v, int l, int n){
if(l <= n){
int sum=0;
for(int i=4; i<=6; i++){
v.push_back(i);
sum += generate(v, l+1, n);
v.erase(v.end() - 1);
}
return sum + numberise(v);
}
else
return 0;
}
int getlevel(vector <int> &v, int num, int key){
if(num < key){
int sum=0;
for(int i=4; i<=6; i++){
v.push_back(i);
sum = 1 + getlevel(v, numberise(v), key);
v.erase(v.end() - 1);
}
return sum;
}
else if(num >= key)
return 0;
}
int main()
{
int k;
cin >> k;
vector <int> v;
cout << endl << getlevel(v, 0, 466546) << endl;
cout << "sum of all nos with no of digits at most " << k << " is = "<< generate(v, 0, k) << endl;
return 0;
}