aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2019-09-22 11:40:23 -0500
committerGitHub2019-09-22 11:40:23 -0500
commitf200f95d9b7b85f063541e719c8150337180edba (patch)
treea6021622567821204167850de3e2ca2ef1d8fd29
parent3630e38cd1ddf403d62e35ede21582facccdc214 (diff)
Create gymnasts.cpp
-rw-r--r--2018/February/Platinum/gymnasts.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/2018/February/Platinum/gymnasts.cpp b/2018/February/Platinum/gymnasts.cpp
new file mode 100644
index 0000000..8904cbf
--- /dev/null
+++ b/2018/February/Platinum/gymnasts.cpp
@@ -0,0 +1,97 @@
+#include <algorithm>
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <vector>
+#include <queue>
+#include <set>
+#include <map>
+#include <unordered_set>
+#include <unordered_map>
+#include <cmath>
+#include <cstring>
+#define init_io(pname) ifstream cin((string)pname+".in"); ofstream cout((string)pname+".out"); ios_base::sync_with_stdio(false); cin.tie(0)
+#define FOR(i, a, b, in) for (int i = (a); i < (b); i += in)
+#define REP(i, a, b) for (int i = (a); i < (b); i++)
+#define RFOR(i, a, b, in) for (int i = (a) - 1; i >= (b); i -= in)
+#define RREP(i, a, b) for (int i = (a) - 1; i >= (b); i--)
+#define trav(a, x) for (auto& a : x)
+#define mp make_pair
+#define pb push_back
+#define f first
+#define s second
+#define lb lower_bound
+#define ub upper_bound
+#define sz(x) (int)x.size()
+#define all(x) begin(x), end(x)
+#define rsz resize
+#define mem(a, b) memset(a, (b), sizeof(a))
+using namespace std;
+typedef string str;
+typedef long long ll;
+typedef long double ld;
+typedef pair<int, int> ii; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd;
+typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ld> vd;
+typedef vector<ii> vii; typedef vector<pl> vpl; typedef vector<pd> vpd;
+constexpr auto INF = (int)1e9;
+constexpr auto LINF = (ll)1e18;
+
+template<int p> struct FF {
+ ll val;
+
+ FF(const ll x = 0) { val = (x % p + p) % p; }
+
+ bool operator==(const FF<p>& other) const { return val == other.val; }
+ bool operator!=(const FF<p>& other) const { return val != other.val; }
+
+ FF operator+() const { return val; }
+ FF operator-() const { return -val; }
+
+ FF& operator+=(const FF<p>& other) { val = (val + other.val) % p; return *this; }
+ FF& operator-=(const FF<p>& other) { *this += -other; return *this; }
+ FF& operator*=(const FF<p>& other) { val = (val * other.val) % p; return *this; }
+ FF& operator/=(const FF<p>& other) { *this *= other.inv(); return *this; }
+
+ FF operator+(const FF<p>& other) const { return FF(*this) += other; }
+ FF operator-(const FF<p>& other) const { return FF(*this) -= other; }
+ FF operator*(const FF<p>& other) const { return FF(*this) *= other; }
+ FF operator/(const FF<p>& other) const { return FF(*this) /= other; }
+
+ static FF<p> pow(const FF<p>& a, ll b) {
+ if (!b) return 1;
+ return pow(a * a, b >> 1) * (b & 1 ? a : 1);
+ }
+
+ FF<p> pow(const ll b) const { return pow(*this, b); }
+ FF<p> inv() const { return pow(p - 2); }
+};
+
+template<int p> FF<p> operator+(const ll lhs, const FF<p>& rhs) { return FF<p>(lhs) += rhs; }
+template<int p> FF<p> operator-(const ll lhs, const FF<p>& rhs) { return FF<p>(lhs) -= rhs; }
+template<int p> FF<p> operator*(const ll lhs, const FF<p>& rhs) { return FF<p>(lhs) *= rhs; }
+template<int p> FF<p> operator/(const ll lhs, const FF<p>& rhs) { return FF<p>(lhs) /= rhs; }
+
+typedef FF<1000000007> MODint;
+
+
+MODint phi(ll n) {
+ MODint ret = n;
+ for (ll p = 2; p * p <= n; p++) {
+ if (n % p == 0) ret -= ret / p;
+ while (n % p == 0) n /= p;
+ }
+ if (n > 1) ret -= ret / n;
+ return ret;
+}
+
+int main() {
+ init_io("gymnasts");
+
+ ll N;
+ cin >> N;
+ MODint ans = phi(N) + 1;
+ for (ll i = 2; i * i <= N; i++) {
+ if (N % i == 0) ans += (MODint(2).pow(i) - 1) * phi(N / i) + (i * i < N) * (MODint(2).pow(N / i) - 1) * phi(i);
+ }
+ cout << ans.val << endl;
+}