forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path56.cpp
More file actions
108 lines (100 loc) · 1.95 KB
/
56.cpp
File metadata and controls
108 lines (100 loc) · 1.95 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
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <set>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long LL;
vector<string> split( const string& s, const string& delim =" " ) {
vector<string> res;
string t;
for ( int i = 0 ; i != s.size() ; i++ ) {
if ( delim.find( s[i] ) != string::npos ) {
if ( !t.empty() ) {
res.push_back( t );
t = "";
}
} else {
t += s[i];
}
}
if (!t.empty() ) {
res.push_back(t);
}
return res;
}
int s2i(string s) {
stringstream ss;
ss << s;
int res;
ss >> res;
return res;
}
string i2s(int n) {
stringstream ss;
ss << n;
string res;
ss >> res;
return res;
}
string add(string a, string b) {
if (a.length() < b.length()) swap(a, b);
int la = a.length(), lb = b.length();
int mm = 0;
REP(i,lb) {
a[i] += b[i] + mm;
mm = a[i] / 10;
a[i] %= 10;
}
FOR(i,lb,la-1) {
a[i] += mm;
mm = a[i] / 10;
a[i] %= 10;
}
if (mm > 0) a = a + char(mm);
return a;
}
string mul(string a, string b) {
string res = "0"; res[0] = char(0);
REP(i,b.length()) {
string t = a;
int mm = 0;
REP(j,t.length()) {
t[j] = t[j] * b[i] + mm;
mm = t[j] / 10;
t[j] %= 10;
}
if (mm > 0) t = t + char(mm);
res = add(res, t);
a = char(0) + a;
}
return res;
}
void run() {
int res = 0;
FOR(i,1,100) {
string si = i2s(i);
reverse(si.begin(), si.end());
REP(q,si.length()) si[q] -= '0';
string t = "1"; t[0] = 1;
t[0] = 1;
FOR(j,1,100) {
t = mul(t, si);
//cout << i << " - " << j << " ";
RFOR(k,t.length()-1,0) cout << char(t[k] + '0');
cout << endl;
int sum = 0;
REP(k,t.length()) sum += t[k];
res = max(res, sum);
}
}
cout << res << endl;
}
int main() {
run();
}