-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob1.cpp
87 lines (67 loc) · 1.17 KB
/
prob1.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<iostream>
using namespace std;
char str[41];
long long arr[41];
long long arrpoi;
long long num;
long long findNumPos(long long x){
long long poww = 1;
long long tempp = arrpoi + 1;
while(tempp > 0){
poww *= 2;
tempp--;
}
poww--;
long long sum = 0;
for(long long i = 1;i<= poww; i++){
tempp = i;
long long product = 1;
long long cou = 0;
for(long long j = 0;j<= arrpoi;j++){
if(((i >> j)&1)==1){
cou++;
product *= arr[j];
}
}
if(cou % 2 == 1){
sum += (x / product );
}else{
sum -= (x / product);
}
}
return sum;
}
long long binsearCH(){
long long s = 1;
long long e = 100000000000000;
long long ans;
while(s <= e){
long long mid = (s + e)/2;
long long temp = findNumPos(mid);
if (temp >= num){
ans = mid;
e = mid-1;
}else{
s= mid + 1;
}
}
return ans;
}
int main(){
long long test_case=1;
//cin>>test_case;
for(long long t = 0 ; t<test_case;t++ ){
cin >> str>> num;
arrpoi = -1;
for(long long i = 0; i< 41;i++){
if(str[i]=='1'){
long long flagg = 0;
if(flagg == 0){
arr[++arrpoi] = i+1;
}
}
}
cout<< binsearCH()<<endl;
}
return 0;
}