From c1597df538b83a79f7fe663c9c34b5076fba4b09 Mon Sep 17 00:00:00 2001 From: Bruno Freitas Tissei <bft15@inf.ufpr.br> Date: Tue, 19 Mar 2019 12:07:50 -0300 Subject: [PATCH] Add ICPC_SA17/J.cpp Signed-off-by: Bruno Freitas Tissei <bft15@inf.ufpr.br> --- contests/ICPC_SA17/J.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 contests/ICPC_SA17/J.cpp diff --git a/contests/ICPC_SA17/J.cpp b/contests/ICPC_SA17/J.cpp new file mode 100644 index 0000000..48ecb03 --- /dev/null +++ b/contests/ICPC_SA17/J.cpp @@ -0,0 +1,67 @@ +#include <bits/stdc++.h> + +#define EPS 1e-6 +#define MOD 1000000007 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +typedef long long ll; +typedef pair<int,int> ii; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + string s; cin >> s; + int n = s.size(); + + int r = 0; + for (int i = 0; i < n; ++i) + r += (s[i] == 'R'); + if (r == n) + return cout << n - 1 << ende, 0; + + vector<int> divs; + for (int i = 2; i*i <= n; ++i) + if (n % i == 0) { + divs.pb(i); + if (i != n / i) + divs.pb(n / i); + } + + vector<int> nums(n, 0); + for (int i = 2; i < n; ++i) + nums[__gcd(i, n)]++; + + int ans = 0; + for (auto i : divs) { + bool poss = false; + for (int j = 0; j < i; ++j) { + bool onlyr = true; + for (int k = j; k < n; k += i) + onlyr &= (s[k] == 'R'); + + if (onlyr) { + poss = true; + break; + } + } + + if (poss) + ans += nums[i]; + } + + cout << ans << ende; + return 0; +} -- GitLab