func_code_string: #include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long ooo = 9223372036854775807ll;   const int _cnt = 1000 * 1000 + 7;   const int _p = 1000 * 1000 * 1000 + 7;   const int N = 1001005;   const double PI = acos(-1.0);   const double eps = 1e-9;   int o(int x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   long long a, b, p, x, r[N], tt = 1, q[N], x0, ans = 0, T = 1, T_rev;   bool v[N];   long long Pow(long long x, long long k) {     long long ans = 1;     for (; k; k >>= 1, (x *= x) %= p)       if (k & 1) (ans *= x) %= p;     return ans;   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &a, &b, &p, &x);     if (a == 1)       if (x < b)         return 0 * printf( 0 n );       else         return 0 * printf( %I64d n , (x - b) / p + 1);     v[1] = 1;     while (1) {       (tt *= a) %= p;       if (v[tt]) break;       v[tt] = 1;       T++;     }     r[1] = tt = 1;     for (int i = (1); i <= (T - 1); ++i) q[(tt *= a) %= p] = i;     q[1] = 0;     T_rev = Pow(T, p - 2);     for (int i = (2); i <= (p - 1); ++i) r[i] = (p - p / i) * r[p % i] % p;     for (int i = (1); i <= (p - 1); ++i) {       if (i > 1 && !q[i]) continue;       long long t = i;       x0 = (r[t] * b % p * T * T_rev + q[t] * p) % (p * T);       if (x < x0) continue;       ans += (x - x0) / (p * T) + 1;     }     printf( %I64d n , ans);     return 0;   }   