提出 #49129894


ソースコード 拡げる

// Problem: AtCoder - AtCoder Beginner Contest 335 (Sponsored by Mynavi) G - Discrete Logarithm Problems
// Url: https://atcoder.jp/contests/abc335/tasks/abc335_g
// T/M Limit: 5000ms 1024MB
// Time: 2024-01-06 21:02:24
// Author: ShaoJia

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define rep(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii<=Ii##_;Ii++)
#define per(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii>=Ii##_;Ii--)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double db;
#define fir first
#define sec second
#define pb push_back
#define eb emplace_back
#define siz(Aa) ((int)(Aa).size())
#define all(Aa) (Aa).begin(),(Aa).end()
#define ckmx(Aa,Bb) (Aa=max(Aa,Bb))
#define ckmn(Aa,Bb) (Aa=min(Aa,Bb))
#define int ll
const int N=200010,V=4e6;
int n,P,a[N];
vector<int> v;
int fpw(int x,int y){
	int res=1;
	while(y){
		if(y&1){
			res=__int128(res)*x%P;
		}
		x=__int128(x)*x%P;
		y>>=1;
	}
	return res;
}
map<int,int> f;
signed main(){ios::sync_with_stdio(false),cin.tie(nullptr);
    cin>>n>>P;
    rep(i,1,V) if((P-1)%i==0){
    	f[i]=0;
    	f[(P-1)/i]=0;
    }
    int x=P-1;
    rep(i,2,V) if(x%i==0){
    	v.emplace_back(i);
    	do{
    		x/=i;
    	}while(x%i==0);
    }
    if(x>1) v.emplace_back(x);
    rep(i,1,n){
    	cin>>x;
    	int y=P-1;
    	for(int j:v){
    		while(y%j==0 && fpw(x,y/j)==1){
    			y/=j;
    		}
    	}
    	a[i]=y;
    	f[y]++;
    }
    // rep(i,1,n) cout<<a[i]<<" \n"[i==i_];
    for(int i:v){
    	for(const auto&[id,val]:f){
    		if(id*i>=P) break;
    		if(f.count(i*id)) f[i*id]+=val;
    	}
    }
    int ans=0;
    rep(i,1,n) ans+=f[a[i]];
    cout<<ans<<"\n";
return 0;}
/*
*/

提出情報

提出日時
問題 G - Discrete Logarithm Problems
ユーザ LXH_cat
言語 C++ 17 (gcc 12.2)
得点 600
コード長 1774 Byte
結果 AC
実行時間 942 ms
メモリ 5656 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 38
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 24 ms 3504 KiB
random_02.txt AC 24 ms 3352 KiB
random_03.txt AC 24 ms 3652 KiB
random_04.txt AC 24 ms 3568 KiB
random_05.txt AC 24 ms 3516 KiB
random_06.txt AC 24 ms 3420 KiB
random_07.txt AC 24 ms 3452 KiB
random_08.txt AC 24 ms 3536 KiB
random_09.txt AC 24 ms 3560 KiB
random_10.txt AC 24 ms 3428 KiB
random_11.txt AC 172 ms 4980 KiB
random_12.txt AC 110 ms 4576 KiB
random_13.txt AC 309 ms 5004 KiB
random_14.txt AC 114 ms 4040 KiB
random_15.txt AC 337 ms 5016 KiB
random_16.txt AC 86 ms 3744 KiB
random_17.txt AC 440 ms 4924 KiB
random_18.txt AC 318 ms 5008 KiB
random_19.txt AC 372 ms 5088 KiB
random_20.txt AC 186 ms 4532 KiB
random_21.txt AC 24 ms 3456 KiB
random_22.txt AC 24 ms 3568 KiB
random_23.txt AC 24 ms 3436 KiB
random_24.txt AC 24 ms 3372 KiB
random_25.txt AC 103 ms 5124 KiB
random_26.txt AC 106 ms 3880 KiB
random_27.txt AC 247 ms 5028 KiB
random_28.txt AC 168 ms 4580 KiB
random_29.txt AC 344 ms 5124 KiB
random_30.txt AC 30 ms 3544 KiB
random_31.txt AC 895 ms 5636 KiB
random_32.txt AC 874 ms 5656 KiB
random_33.txt AC 942 ms 5640 KiB
random_34.txt AC 869 ms 5636 KiB
random_35.txt AC 896 ms 5604 KiB
sample_01.txt AC 24 ms 3480 KiB
sample_02.txt AC 24 ms 3504 KiB
sample_03.txt AC 24 ms 3420 KiB