"NOIP2019 simulation game day1" cute girl tuple

"NOIP2019 simulation game day1" cute girl tuple

内存限制:256 MiB时间限制:1000 ms输入文件:pairs.in输出文件:pairs.out
| Subject description |
|: ------ |
| W is a lovely little girl, she liked tuple.
W now have a small prime \ (P \) and a length \ (n-\) sequence of integers \ (A \) , and an integer \ (K \) , and she has recently in love with a particular tuple \ (\ ~ RM Shmily Pair \) .
W is small that a tuple \ ((i, j) \ ) is \ (\ RM Pair Shmily. ~ \) , If and only if \ ((a_i + a_j) ( a_i ^ 2 + a_j ^ 2) \ equiv k \ MOD P \) , where \ (. 1 \ leqslant I <J \ n-leqslant \) .
Now she has a small W want to know the sequence of integers \ (a \) , the number of bins and is \ (\ ~ RM Shmily Pair \) . |

Input Format
The first row of three integers \ (n-, P, K \) .
The second row \ (n-\) integer, describes a sequence of integers \ (A \) .
Output Format
Only one row, a integer indicating \ (\ rm Shmily ~ Pair \ ) number.
Sample
Sample input
6 7 2
1 2 3 4 5 6
Sample Output
3
Data range and tips
For \ (30 \% \) data, \ (n-\ leqslant. 4 ^ 10 \) .
For \ (60 \% \) data, \ (n-\ leqslant. 3 \ ^ 10. 5 Times \) .
For \ (100 \% \) data, \ (2 \ leqslant n-\ leqslant. 5 \ Times 10 ^. 6 \) , \ (2 \ leqslant P \ leqslant 10 ^. 9 \) , \ (0 \ leqslant K <P \) .
prompt
We first look at the formula of:
\ ((A ^ 2_i - A ^ 2_j) (A ^ A ^ 2_j 2_i +) \ equiv k (a_i - a_j) \ the p-MOD \)
\ (A ^ 4_i - A ^ 4_j \ equiv ka_i - ka_j \ MOD P \)
\ (4_i A ^ - A ^ ≡ ka_i 4_j - ka_j \ MOD P \)
Since \ (K \) is determined, we will \ (a ^ 4_i -ka_i \) modulo after thrown \ (map \) , and then you can count how many of the same number and it.

Code

#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>

std::ifstream fin("pairs.in");
std::ofstream fout("pairs.out");

int main(){
    fin.sync_with_stdio(false);
    fout.sync_with_stdio(false);
    int n,p,k,ans=0;
    fin>>n>>p>>k;
    std::map<int,int> s;
    long long x;
    for(int i=0,tmp;i<n;i++){
        fin>>x;
        tmp=(((((((((x%p)*x)%p)*x%p)*x)%p)-(k*x%p))+p)%p)%p;
        ans+=s[tmp];
        s[tmp]++;
    }
    fout<<ans<<std::endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/ZhaoChongyan/p/11798491.html