Advertisement
Guest User

Untitled

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