-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchefcode.cpp
More file actions
97 lines (87 loc) · 1.36 KB
/
chefcode.cpp
File metadata and controls
97 lines (87 loc) · 1.36 KB
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
88
89
90
91
92
93
94
95
96
97
// Author: yvdyash
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll n,k,a[100],ans=0;
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
ll k1=1,f1=0,k2=1,f2=0;
ll x[50000],y[50000];
x[0]=1;y[0]=1;
for (int i=0; i<(1<<n/2); i++)
{
ll s = 1;
for (int j=0; j<n/2; j++)
{
if (i & (1<<j))
{
if((log(s)+log(a[j]))<=log(pow(10,18)))
{
s *= a[j];
f1=1;
}
else
{
f1=0;
break;
}
}
}
if(f1)
{
x[k1]=s;
k1++;
}
}
for (int i=0; i<(1<<(n-n/2)); i++)
{
ll s = 1;
for (int j=0; j<(n-n/2); j++)
{
if (i & (1<<j))
{
if((log(s)+log(a[j+n/2]))<=log(pow(10,18)))
{
s *= a[j+n/2];
f2=1;
}
else
{
f2=0;
break;
}
}
}
if(f2)
{
y[k2] =s ;
k2++;
}
}
ll sizex=k1;
ll sizey=k2;
sort(y,y+sizey);
ll p,z;
for(int i=0;i<sizex;i++)
{
if(x[i]<=k)
{
p = lower_bound(y, y+sizey,k/x[i])- y ;
z=p+1;
while(y[z]==k/x[i])
{
p=z;
z++;
}
if (p == sizey || y[p] != (k/x[i]))
p--;
p++;
}
else p=0;
ans+=p;
}
cout<<ans-1<<"\n";
}