zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    软件工程-事后Postmortem 会议
    软件工程-项目复审
    团队作业-冲刺博客(日更)
    团队作业-冲刺博客(任务与计划)
    团队作业-需求改进&系统设计
    软件工程团队作业-需求规格说明书
    TooBug,出撃!
    FileReader
    Javascript刷新页面的几种方法:
    软件工程-个人项目
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/11158260.html
Copyright © 2011-2022 走看看