-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultipleOf17.cpp
375 lines (323 loc) · 7.54 KB
/
multipleOf17.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("multipleOf17.in");
ofstream fout("multipleOf17.out");
struct sint
{
vector<int> v;
sint()
{
//默认构造函数
}
sint(long long i)
{
//从string构造数据
this->read(std::to_string(i));
}
sint(string s)
{
//从string构造数据
this->read(s);
}
sint(vector<int> & s)
{
//从vector<int>构造数据
this->v=s;
}
bool operator<(const sint &newbigInt)
{
int size0 = v.size();
int size1 = newbigInt.v.size();
if (size0 != size1)
{
return size0 < size1;
}
else
{
for (int i = 0; i <= size0 - 1; ++i)
{
if (v[i] != newbigInt.v[i])
{
return v[i] < newbigInt.v[i];
}
}
}
return false;
}
bool operator>(const sint &newbigInt)
{
int size0 = v.size();
int size1 = newbigInt.v.size();
if (size0 != size1)
{
return size0 > size1;
}
else
{
for (int i = 0; i <= size0 - 1; ++i)
{
if (v[i] != newbigInt.v[i])
{
return v[i] > newbigInt.v[i];
}
}
}
return false;
}
bool operator<=(const sint &newbigInt)
{
return !((*this) > newbigInt);
}
bool operator>=(const sint &newbigInt)
{
return !((*this) < newbigInt);
}
bool operator==(const sint &newbigInt)
{
int size0 = v.size();
int size1 = newbigInt.v.size();
if (size0 != size1)
{
return false;
}
else
{
for (int i = 0; i <= size0 - 1; ++i)
{
if (v[i] != newbigInt.v[i])
{
return false;
}
}
}
return true;
}
sint operator+(const sint &newbigInt)
{
sint result;
vector<int> big, small;
if (v.size() > newbigInt.v.size())
{
big = v;
small = newbigInt.v;
}
else
{
small = v;
big = newbigInt.v;
}
int size0 = big.size();
int size1 = small.size();
vector<int> ans(size0);
for (int i = 1; i <= size0 - size1; ++i)
{
small.insert(small.begin(), 0);
}
int last = 0;
for (int i = size0 - 1; i >= 0; --i)
{
int nowNum = last + big[i] + small[i];
ans[i] = nowNum % 10;
last = nowNum >= 10;
if (i == 0 && last == 1)
{
ans.insert(ans.begin(), 1);
}
}
result.v = ans;
return result;
}
sint operator-(const sint &newbigInt)
{
sint result;
if ((*this) == newbigInt)
{
vector<int> temp = {0};
result.v = temp;
return result;
}
vector<int> big, small;
if (v.size() >= newbigInt.v.size())
{
big = v;
small = newbigInt.v;
}
else
{
small = v;
big = newbigInt.v;
}
int size0 = big.size();
int size1 = small.size();
vector<int> ans(size0);
for (int i = 1; i <= size0 - size1; ++i)
{
small.insert(small.begin(), 0);
}
int last = 0;
for (int i = size0 - 1; i >= 0; --i)
{
if (last == 1)
{
--big[i];
}
if (big[i] < small[i])
{
last = 1;
big[i] += 10;
}
else
{
last = 0;
}
ans[i] = big[i] - small[i];
}
while(ans[0] == 0)
{
ans.erase(ans.begin());
}
result.v = ans;
return result;
}
sint operator*(const sint &newbigInt)
{
sint result;
vector<int> big, small;
if (v.size() > newbigInt.v.size())
{
big = v;
small = newbigInt.v;
}
else
{
small = v;
big = newbigInt.v;
}
int size0 = big.size();
int size1 = small.size();
vector<int> empty = {0};
result.v = empty;
sint temp0(big);
for (int i = size1 - 1; i >= 0; --i)
{
sint temp1(empty);
for (int c = 1; c <= small[i]; ++c)
{
temp1 = temp1 + temp0;
}
for (int c = 1; c <= size1 - i - 1; ++c)
{
temp1.v.push_back(0);
}
result = result + temp1;
}
return result;
}
string toString()
{
string ans = "";
int size = this->v.size();
for (int i = 0; i <= size - 1; ++i)
{
ans += this->v[i] + '0';
}
return ans;
}
sint operator/(const sint &newbigInt)
{
sint result(0);
sint a = *(this);
sint b = newbigInt;
int tens = a.v.size() - b.v.size();
while (a >= b)
{
sint temp0 = b;
sint temp1(1);
sint ten(10);
for (int i = 1; i <= tens; ++i)
{
temp0.v.push_back(0);
temp1.v.push_back(0);
}
while (a >= temp0)
{
result = result + temp1;
a = a - temp0;
}
--tens;
}
return result;
}
sint operator%(const sint &newbigInt)
{
return (*this) - ((*this) / newbigInt) * newbigInt;
}
void read(string s)
{
int size = s.size();
this->v.clear();
for (int i = 0; i <= size - 1; ++i)
{
if (s[i] >= '0' && s[i] <= '9')
{
this->v.push_back(s[i] - '0');
}
}
}
sint pow(const int times)
{
int n = times;
sint result(1);
sint nowNum = *this;
while (n > 0)
{
if (n & 1) //判断奇偶,等同于 n % 2 == 1;
{
result = result * nowNum;
}
nowNum = nowNum * nowNum;
n >>= 1; //等同于 n /= 2;
}
return result;
}
};
int main()
{
sint n100(100);
sint n17(17);
sint n5(5);
sint n0(0);
while (true)
{
string in;
fin >> in;
if (in == "0")
{
break;
}
sint n(in);
while (n > n100)
{
sint temp(n.v.back());
n.v.pop_back();
n = n - temp * n5;
}
if (n % n17 == n0)
{
fout << 1 << '\n';
}
else
{
fout << 0 << '\n';
}
}
}