• CodeForces


    You are given a prime number pp, nn integers a1,a2,,ana1,a2,…,an, and an integer kk.

    Find the number of pairs of indexes (i,j)(i,j) (1i<jn1≤i<j≤n) for which (ai+aj)(a2i+a2j)kmodp(ai+aj)(ai2+aj2)≡kmodp.

    Input

    The first line contains integers n,p,kn,p,k (2n31052≤n≤3⋅105, 2p1092≤p≤109, 0kp10≤k≤p−1). pp is guaranteed to be prime.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (0aip10≤ai≤p−1). It is guaranteed that all elements are different.

    Output

    Output a single integer — answer to the problem.

    Examples
    input
    Copy
    3 3 0
    0 1 2
    
    output
    Copy
    1
    input
    Copy
    6 7 2
    1 2 3 4 5 6
    
    output
    Copy
    3


    题意:
    问有多少对i,j,使得a[i],a[j]满足题干中的式子。
    思路:
    两边同乘(a[i]-a[j]),再把a[i],a[j]分到式子两边即可。

    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<stack>
    #include<queue>
    #include<map>
    #include<set>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    
    #define fuck(x) cout<<#x<<" = "<<x<<endl;
    #define debug(a, x) cout<<#a<<"["<<x<<"] = "<<a[x]<<endl;
    #define ls (t<<1)
    #define rs ((t<<1)|1)
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 300086;
    const int maxm = 100086;
    const int inf = 0x3f3f3f3f;
    const ll Inf = 999999999999999999;
    const int mod = 1000000007;
    const double eps = 1e-6;
    const double pi = acos(-1);
    
    
    map<ll,ll>mp;
    int main() {
    //    ios::sync_with_stdio(false);
    //    freopen("in.txt", "r", stdin);
    
        ll p,n,k;
        scanf("%lld%lld%lld",&n,&p,&k);
        ll ans = 0;
        for(int i=1;i<=n;i++){
            ll x;
            scanf("%lld",&x);
            ll num = (x*x%p*x%p*x%p - (k*x)%p+p+p)%p;
    //        fuck(num)
            ans+=mp[num];
            mp[num]++;
        }
        printf("%lld
    ",ans);
    
        return 0;
    }
    View Code
  • 相关阅读:
    selenium 浏览器操作
    selenium 4.0新特性及新旧api对比
    Selenium123介绍
    selenium元素定位(三) css定位方法
    selenium 安装和启动
    Selenium元素定位(一)30+1+5种方式
    软件开发经验收集
    spring+hibernate架构中Dao访问数据库的几种方法
    某励志书4
    PHP的Foreach
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/11158260.html
Copyright © 2020-2023  润新知