Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define sz(x) ((int) (x).size())
  6. #define all(x) (x).begin(), (x).end()
  7. #define fi first
  8. #define se second
  9. #define mp make_pair
  10. #define pb push_back
  11. #define re return
  12. #define endl '\n'
  13.  
  14. using ll = long long;
  15. using ull = unsigned long long;
  16. using ii = pair<int, int>;
  17. using vi = vector<int>;
  18. using vll = vector<ll>;
  19. using vii = vector<ii>;
  20. using ld = long double;
  21.  
  22. template <class T> T abs (T x) { re x > 0 ? x : -x; }
  23. template <class T> T sqr (T x) { re x * x; }
  24.  
  25. const ld pi = acos(1.);
  26. const ll inf = 1e10 + 7;
  27. const int N = 1e6 + 17;
  28.  
  29. ll n;
  30.  
  31. ll mul (ll x, ll y, ll mod) {
  32. ll ans = 0;
  33. while (y) {
  34. if (y & 1) ans = (ans + x) % mod;
  35. x = (x + x) % mod;
  36. y >>= 1;
  37. }
  38. re ans;
  39. }
  40.  
  41. ll power (ll x, ll p, ll mod) {
  42. ll ans = 1 % mod;
  43. while (p) {
  44. if (p & 1) ans = mul (ans, x, mod);
  45. x = mul (x, x, mod);
  46. p >>= 1;
  47. }
  48. re ans;
  49. }
  50.  
  51. ll myrand() {
  52. ll a = rand() + (rand() << 15);
  53. re rand() + (rand() << 15) + (a << 30);
  54. }
  55.  
  56. bool get (ll s, ll d, ll n) {
  57. ll a = 1 + myrand() % (n - 1);
  58. if (power(a, n - 1, n) != 1) re false;
  59. a = power (a, d, n);
  60. if (a == 1) re true;
  61. for (int i = 0; i < s; i++) {
  62. if (a == n - 1) re true;
  63. a = mul (a, a, n);
  64. }
  65. re false;
  66. }
  67.  
  68. bool is_prime (ll n) {
  69. ll s = 0, d = n - 1;
  70. while (d % 2 == 0) { s++; d /= 2; }
  71. for (int i = 0; i < 10; i++)
  72. if (!get(s, d, n)) re false;
  73. re true;
  74. }
  75.  
  76. ll func (ll x, ll n) {
  77. re (mul (x, x, n) + 1) % n;
  78. }
  79.  
  80. map<ll, int> ans;
  81.  
  82. void go (ll n) {
  83. if (n < inf) {
  84. for (ll j = 2; j * j <= n; j++)
  85. while (n % j == 0) { ans[j]++; n /= j; }
  86. if (n > 1) ans[n]++;
  87. re;
  88. }
  89. if (is_prime(n)) { ans[n]++; re; }
  90. ll x = 1 + rand() % (n - 1);
  91. ll y = x, d = 1;
  92. while (d == 1) {
  93. x = func (x, n);
  94. y = func (func (y, n), n);
  95. d = (n + y - x) % n;
  96. d = __gcd(d, n);
  97. }
  98. go (d), go (n / d);
  99. }
  100.  
  101. int main() {
  102. srand(time(0));
  103. cin >> n;
  104. go(n);
  105. int cnt = 0, y = 0;
  106. for (auto x : ans) cnt += (x.se & 1), y += x.se / 2;
  107. if (2 * y > cnt) cout << "Vasya";
  108. else cout << "Petya";
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement