Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int N = 5e5;
- int n, p, phi, tmp;
- long long res = 0;
- map<long long, int> Map;
- long long power(long long a, long long b, long long j)
- {
- if (b == 0)
- {
- return 1 % j;
- }
- long long t = power(a, b/2, j);
- if (b % 2 == 0)
- {
- return (t * t) % j;
- }
- else
- {
- return (((t * t) % j) * a) % j;
- }
- }
- long long inv(int a)
- {
- return power(a, phi - 1, p);
- }
- void read()
- {
- cin >> n >> p;
- tmp = p, phi = p;
- for (int i = 2; i * i <= tmp; ++ i)
- {
- if (tmp % i == 0)
- {
- while (tmp % i == 0)
- {
- tmp /= i;
- }
- phi -= phi/i;
- }
- }
- if (tmp != 1)
- {
- phi -= phi/tmp;
- }
- }
- void solve()
- {
- int a;
- for (int i = 1; i <= n; ++ i)
- {
- cin >> a;
- a = (a - 1 + p) % p;
- if (__gcd(a, p) == 1)
- {
- res += Map[inv(a)];
- }
- ++Map[a];
- }
- cout << res;
- }
- /// inv(x) = x ^ (phi - 1) % p
- /// x * inv(x) % p == 1
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- read();
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement