Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define sz(x) ((int) (x).size())
- #define all(x) (x).begin(), (x).end()
- #define fi first
- #define se second
- #define mp make_pair
- #define pb push_back
- #define re return
- #define endl '\n'
- using ll = long long;
- using ull = unsigned long long;
- using ii = pair<int, int>;
- using vi = vector<int>;
- using vll = vector<ll>;
- using vii = vector<ii>;
- using ld = long double;
- template <class T> T abs (T x) { re x > 0 ? x : -x; }
- template <class T> T sqr (T x) { re x * x; }
- const ld pi = acos(1.);
- const ll inf = 1e10 + 7;
- const int N = 1e6 + 17;
- ll n;
- ll mul (ll x, ll y, ll mod) {
- ll ans = 0;
- while (y) {
- if (y & 1) ans = (ans + x) % mod;
- x = (x + x) % mod;
- y >>= 1;
- }
- re ans;
- }
- ll power (ll x, ll p, ll mod) {
- ll ans = 1 % mod;
- while (p) {
- if (p & 1) ans = mul (ans, x, mod);
- x = mul (x, x, mod);
- p >>= 1;
- }
- re ans;
- }
- ll myrand() {
- ll a = rand() + (rand() << 15);
- re rand() + (rand() << 15) + (a << 30);
- }
- bool get (ll s, ll d, ll n) {
- ll a = 1 + myrand() % (n - 1);
- if (power(a, n - 1, n) != 1) re false;
- a = power (a, d, n);
- if (a == 1) re true;
- for (int i = 0; i < s; i++) {
- if (a == n - 1) re true;
- a = mul (a, a, n);
- }
- re false;
- }
- bool is_prime (ll n) {
- ll s = 0, d = n - 1;
- while (d % 2 == 0) { s++; d /= 2; }
- for (int i = 0; i < 10; i++)
- if (!get(s, d, n)) re false;
- re true;
- }
- ll func (ll x, ll n) {
- re (mul (x, x, n) + 1) % n;
- }
- map<ll, int> ans;
- void go (ll n) {
- if (n < inf) {
- for (ll j = 2; j * j <= n; j++)
- while (n % j == 0) { ans[j]++; n /= j; }
- if (n > 1) ans[n]++;
- re;
- }
- if (is_prime(n)) { ans[n]++; re; }
- ll x = 1 + rand() % (n - 1);
- ll y = x, d = 1;
- while (d == 1) {
- x = func (x, n);
- y = func (func (y, n), n);
- d = (n + y - x) % n;
- d = __gcd(d, n);
- }
- go (d), go (n / d);
- }
- int main() {
- srand(time(0));
- cin >> n;
- go(n);
- int cnt = 0, y = 0;
- for (auto x : ans) cnt += (x.se & 1), y += x.se / 2;
- if (2 * y > cnt) cout << "Vasya";
- else cout << "Petya";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement