-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
87 lines (68 loc) · 1.35 KB
/
C.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll a, b;
vector<ll> suffix;
ll binpow(ll a, ll b, ll m)
{
ll res = 1;
a %= m;
while (b) {
if (b & 1) {
res = (res * a) % m;
}
a = (a * a) % m;
b /= 2;
}
return res;
}
void solve()
{
cin >> s >> a >> b;
int n = (int)s.size();
suffix.resize(n, -1);
ll val = 0;
string t;
for (int i = n - 1; i >= 0 ; i--) {
val = ((s[i] - '0') * binpow(10LL, n - i - 1, b) + val) % b;
suffix[i] = val;
}
/*for (auto &x : suffix) cout << x << ' ';
cout << '\n';*/
int partitionIndex = -1;
val = 0;
for (int i = 0; i < n - 1; i++) {
val = (val * 10LL + (s[i] - '0')) % a;
if (val == 0) {
while (i < n - 1 && s[i + 1] == '0') i++;
if (i >= n - 1) break;
if (suffix[i + 1] == 0) {
partitionIndex = i;
break;
}
}
}
// cout << "idx: " << partitionIndex << '\n';
if (partitionIndex == -1) {
cout << "NO\n";
return;
}
cout << "YES\n";
cout << s.substr(0, partitionIndex + 1) << '\n';
cout << s.substr(partitionIndex + 1, n - (partitionIndex + 1)) << '\n';
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//freopen("Error.txt", "w", stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}