Codeforces 1188B Count Pairs (同余+分离变量)

题意:

给一个3e5的数组,求(i,j)对数,使得$(a_i+a_j)(a_i^2+a_j^2)\equiv k\ mod\ p$

思路:

化简$(a_i^4-a_j^4)\equiv k(a_i-a_j)\ mod\ p$

分离变量$a_i^4-ka_i\equiv (a_j^4-ka_j)\ mod\ p$

于是就变成了常规题

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
//#define lowbit(x) ((x)&(-x)) 

using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);
ll a[maxn];
map<ll, ll>ma;
int main(){
    ll n, p, k;
    scanf("%lld %lld %lld", &n, &p, &k);
    for(int i = 1; i <= n; i++){
        scanf("%lld", &a[i]);
        ll x = a[i];
        ll res = x*x%p*x%p*x%p-k*x%p;
        res=(res+p)%p;
        ma[res]++;
    }
    ll ans = 0;
    for(auto it = ma.begin(); it != ma.end(); it++){
        ll x = (*it).sc;
        //printf("%lld %lld\n", (*it).fst, x);
        ans+=(x-1)*x/2;
    }
    printf("%lld",ans);
    return 0;        
}

/*
 */

 

posted @ 2019-07-06 22:43  wrjlinkkkkkk  阅读(268)  评论(0编辑  收藏  举报