ZROIの#1004

ZROIの#1004

私はより多くの野菜を持っているので、観察は十分ではありませんので、半分の時間のためのカードのペア、数学的基礎対象の小さなペアを必要としています。
我々は、元のタイプ:

\ [(X ^ 2 + Y)^ 2当量\(X ^ 2Y)^ 2 \ PMODのP \]
\ [X ^ 4 + 2X ^ 2Y + Y ^ 2 \当量X ^ 4-2x ^ 2Y + Y ^ 2 \ PMODのP \]
\ [2X ^ 2Y \当量-2X ^ 2Y \ PMODのP \]
\ [4Xは^ 2Y \]は1つの\ PMOD Pが\をEQUIV

あいあい愛!\(y軸の\は)それはないです\(^ 4xの2 \)金型に\(P \)それの意味の逆?

タイトルにも確実に\(のp \)は素数なので、逆一意である必要があります。

元のシーケンス内の要素が対で互いに素性を確保するが、最も可能性の高い、同じタイプの残りの要素がありますが。

逆に、実際に残っているクラスの一つであるので、我々は、統計の元のシーケンスの残りの行のいずれかを実行する必要があります。

このペアは行われていますか。

いいえ、ありません
。また、逆の要素が存在しないことを考慮すべきである
弾性率は素数ですが、平均的な数値のための逆の要素がなければならないが、残留のカテゴリがあり、例外である:\(0 \)
もちろん、\(0 \ )の逆を持つべきではありません。
これは、これが行わ本当の問題です。

\(コード:\)

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define pii pair < int , int >
#define one first
#define two second
#define rint read<int>
#define int long long
#define pb push_back

using std::queue ;
using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;

template < class T >
    inline T read () {
        T x = 0 , f = 1 ; char ch = getchar () ;
        while ( ch < '0' || ch > '9' ) {
            if ( ch == '-' ) f = - 1 ;
            ch = getchar () ;
        }
       while ( ch >= '0' && ch <= '9' ) {
            x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
            ch = getchar () ;
       }
   return f * x ;
}

const int N = 1e5 + 100 ;

std::map < int , int > mk ;
int n , ans , mod , v[N] ;

inline int quick (int a , int p) {
    int res = 1 ;
    while ( p ) {
        if ( p & 1 ) res = ( res * a ) % mod ;
        a = a * a % mod ; p >>= 1 ;
    }
    return res % mod ;
}

inline int check (int ll , int rr , int x) {
    int l = ll , r = rr ;
    while ( l <= r ) {
        int mid = ( l + r ) >> 1 ;
        if ( v[mid] % mod == x ) return mid ;
        if ( v[mid] % mod < x ) l = mid + 1 ;
        if ( v[mid] % mod > x ) r = mid - 1 ;
    }
    return - 1 ;
}

signed main (int argc , char * argv[]) {
    n = rint () ; mod = rint () ;
    rep ( i , 1 , n ) v[i] = rint () ;
    rep ( i , 1 , n ) { v[i] %= mod ; ++ mk[v[i]] ; }
    sort ( v + 1 , v + n + 1 ) ;
    for (int i = 1 ; i <= n ; ++ i) {
        if ( ! v[i] ) continue ;
        int tmp = ( v[i] * v[i] << 2 ) % mod ;
        int inv = quick ( tmp , mod - 2 ) % mod ;
        int pos = check ( 1 , n , inv ) ;
        if ( pos == - 1 || pos == i ) continue ;
        ans += mk[v[pos]] ;
    }
    printf ("%lld\n" , ans ) ;
    return 0 ;
}

おすすめ

転載: www.cnblogs.com/Equinox-Flower/p/11571383.html