-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSP-A very easy problem.cpp
173 lines (126 loc) · 3.31 KB
/
SP-A very easy problem.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#include<bits/stdc++.h>
#include<cmath>
#include<cstdlib> //for qsort
#include<cstdio>
#define rep(x,a,b) for(x=a;x<b;x++)
#define reptill(x,a,b) for(x=a;x<=b;x++)
#define scani(x) scanf("%d",&x)
#define scan2i(x,y) scanf("%d %d",&x,&y)
#define scan3i(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define scanfl(x) scanf("%f",&x)
#define scanc(x) scanf("%c",&x)
#define scand(x) scanf("%lf",&x)
#define scanll(x) scanf("%lli",&x)
#define scan2ll(x,y) scanf("%lli %lli",&x,&y)
#define scan3ll(x,y) scanf("%lli %lli %lli",&x,&y,&z);
#define scanl(x) scanf("%ld",&x)
#define scans(x) scanf("%s",x)
#define printi(x) printf("%d\n",x)
#define printl(x) printf("%ld\n",x)
#define printll(x) printf("%lli\n",x)
#define printd(x) printf("%lf\n",x)
#define printfl(x) printf("%f\n",x)
#define printc(x) printf("%c\n",x)
#define prints(x) printf("%s\n",x);
#define sloop(x) loop(i,0,strlen(x)-1)
#define whole(x) x.begin(),x.end()
#define pb push_back
#define newl cout<<"\n"
#define F first
#define S second
#define FILL(A,value) memset(A,value,sizeof(A))
inline bool inc_range(int x,int y,int z) { return ((x>=y)&&(x<=z)); }
inline bool ex_range(int x,int y,int z) { return ((x>y)&&(x<z)); }
inline bool is_either(int x,int y,int z) { return ((x==y)||(x==z)); }
//maths
#define PI acos(-1)
#define INTmax numeric_limits<int>::max()
#define LLmax numeric_limits<ll>::max()
#define ULLmax numeric_limits<ull>::max()
#define INTmin numeric_limits<int>::min()
using namespace std;
template<typename type=int>
void get_arr(type a[],type n) {for(type i=0;i<n;i++) cin>>a[i];}
template<typename type=int>
void show_arr(type a[],type n=1) {for(type i=0;i<n;i++) cout<<a[i]<<" ";}
template<typename type=int>
inline type max3(type a,type b,type c){ return max(max(a,b),c);}
inline void FAST_IO(){ios_base::sync_with_stdio(false);}
template<typename type>
type fastpow(type a, type b, type c) { type ans=1; while(b != 0){ if(b%2 == 1) ans=(ans*a)%c; a=(a*a)%c; b /= 2; } return ans; }
template<typename type>
type fastpow(type a, type b){ type ans=1; while(b != 0){ if(b%2 == 1) ans=(ans*a); a=(a*a); b /= 2; } return ans; }
#define SIZE int(1e3)+1
#define MOD
#define debug
//#define Online_judge
//ofstream cout("op");
string ans;
void print(int x)
{
// cout<<"2(";
ans+="2(";
if(x==0 or x==1)
{
// cout<<x<<")";
if(x) ans+="1)";
else ans+="0)";
return;
}
while(x){
print(log2(x));
x=x-fastpow(2,(int)log2(x));
if(x)
ans+="+";
//cout<<"+";
}
// cout<<")";
ans+=")";
}
int main()
{
FAST_IO();
//ifstream cin("ip");
ofstream cout("op");
int pw ;
int ip[]={137,1315,73,136,255,1384,16385};
int indx=0;
while(indx<7)
{
ans.erase(whole(ans));
int x=ip[indx++];
cout<<x<<"=";
while(x){
print(log2(x));
x=x-fastpow(2,(int)log2(x));
if(x)
ans+="+";
//cout<<"+";
}
/*
while(x & x-1){
//flag=true;
//cout<<log2(x);
pw=ll(log2(x));
cout<<pw<<" ";
x-=fastpow(ll(2),pw);
}
if((x & x-1) ==0)
cout<<log2(x)<<" ";
*/
//cout<<ans<<"\n";
string newans="";
int i=0;
while(i<ans.size())
{
if(i+4<=ans.size() and ans.substr(i,4).compare("2(1)")==0)
newans+="2",i+=4;
//cout<<"gottcha at i="<<i<<endl,newans+="2",cout<<"ans="<<ans<<"\n"<<"new="<<newans<<endl,i+=4;
else newans+=ans.substr(i++,1);
}
cout<<newans<<"\n";
}
}