-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiy.cpp
More file actions
91 lines (90 loc) · 1.29 KB
/
biy.cpp
File metadata and controls
91 lines (90 loc) · 1.29 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
#include <bits/stdc++.h>
using namespace std;
int checkbitset(int y);
int gcd(int a[],int l);
int bitmask(int i,int n,char s[],int x,int y,int m);
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
char s[n];
cin>>s;
int m,x,y,ans,max=0;
cin>>m>>x>>y;
for(int i=0;i<(1<<(n-1));i++)
{
ans=bitmask(i,n,s,x,y,m);
if(max<ans)
max=ans;
}
cout<<max<<endl;
}
return 0;
}
int checkbitset(int y)
{
int c=0;
for(int i=0;i<32;i++)
{
if(y&(1<<i))
c++;
}
return c;
}
int bitmask(int i,int n,char s[],int x1,int y,int m)
{
n-=1;
int a[n],prev=0,l=0,t=0,arr[n],k;
if(x1>checkbitset(i)||y<checkbitset(i))
return 0;
for(int j=0;j<n;j++)
{
t=0;
if(i&(1<<j))
{
/*char c[j-prev+2];
int prev;
for(int k=j;k>=prev;k--)
{
c[t++]=s[n-k];
}
a[l++]=atoi(c);
cout<<a[l-1]<<endl;
prev=j+1;*/
arr[t++]=n-j;
}
}
arr[t]=0;
for(int j=0;j<=t;j++)
arr[j]=arr[t-1-j];
for(int j=0;j<=t;j++)
{
k=0;
char c[arr[t]-arr[t-1]+1];
for(int p=arr[t-1];p<arr[t];p++)
c[k++]=s[p];
a[l++]=atoi(c);
}
/*char c[n-prev];
int x=prev;
while(prev<=n-1)
{
c[prev-x-1]=s[prev+1];
prev++;
}
a[l++]=atoi(c);*/
return gcd(a,l);
}
int gcd(int a[],int l)
{
int b=a[0];
for(int i=0;i<l;i++)
{
b=(__gcd(b,a[i+1]));
}
return b;
}