QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735182 | #9705. Multiply | icealsoheat | TL | 7ms | 12032kb | C++20 | 6.7kb | 2024-11-11 17:57:03 | 2024-11-11 17:57:03 |
Judging History
answer
#pragma GCC optimize(3) //O2优化开启
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lll __int128
#define int long long
typedef pair<int,int> PII;
const int mod=998244353;
// const int MX=0x3f3f3f3f3f3f3f3f;
/*------------------------------Base------------------------------*/
inline ll mul(ll a, ll b, const ll M){
ll d =a*(long double)b/M;
ll ret =a*b-d*M;
if(ret < 0)
ret +=M;
if(ret >= M)
ret -=M;
return ret;
}
inline ll plus2(ll a, ll b, const ll M){
ll d =(a+(long double)b)/M+0.5;
ll ret =a+b-d*M;
if(ret < 0)
ret +=M;
return ret;
}
inline lll plus1(const lll a, const lll b, const lll M){
lll c =a+b;
if(c >= M)
return c-M;
else
return c;
}
ll Pow(ll x, ll k, const ll M){
ll ret =1;
for(; k; x =mul(x, x, M), k >>=1) if(k&1) ret =mul(ret, x, M);
return ret;
}
ll gcd(ll a, ll b){
while(b) b ^=a ^=b ^=a %=b;
return a;
}
inline ll Abs(ll x){ return (x < 0) ? -x : x; }
/*------------------------------Rand------------------------------*/
static std::mt19937 engine;
/*------------------------------Miller Robin------------------------------*/
bool mr(ll p){
if(p < 2) return 0;
if(p == 2) return 1;
if(p == 3) return 1;
std::uniform_int_distribution<ll> Rand(2, p-2);
ll d =p-1, r =0;
while(!(d&1)) ++r, d >>=1;
for(ll k =0; k < 10; ++k){
/*[2, p-2]*/
ll a =Rand(engine);
ll x =Pow(a, d, p);
if(x == 1 || x == p-1) continue;
for(int i =0; i < r-1; ++i){
x =mul(x, x, p);
if(x == p-1) break;
}
if(x != p-1) return 0;
}
return 1;
}
/*------------------------------Pollard Rho------------------------------*/
using std::min;
/*貌似 -c 在本题的数据的效率高些 (0.2s),原因尚不确定*/
inline ll getnext(ll x, ll c, ll n){
return plus1(mul(x, x, n), -c, n);
}
ll pr(ll n){
/*因为初始跳两步的原因,下面写法均没法分解 4 (即使下面的 Rand 范围设置为 [0, n-1] )*/
if(n == 4) return 2;
std::uniform_int_distribution<ll> Rand(3, n-1);
ll x =Rand(engine), y =x;
ll c =Rand(engine);
ll d =1;
/*以下两种写法的期望复杂度都是正确的,但写法 1 的表现更好*/
/*----------写法 1----------*/
x =getnext(x, c, n);
y =getnext(y, c, n), y =getnext(y, c, n);
for(int lim =1; x != y; lim =min(128ll, lim<<1)){/*提升约 0.1s */
// for(int lim =1; x != y; lim =lim<<1){
ll cnt =1;
for(int i =0; i < lim; ++i){
ll tmp =mul(cnt, Abs(plus1(x, -y, n)), n);
if(!tmp)/*提升约 0.6s;这时要么原先的 cnt 含 n 质因数 (这时 x-y 也含 ),要么 x-y == 0*/
break;
cnt =tmp;
x =getnext(x, c, n);
y =getnext(y, c, n), y =getnext(y, c, n);
}
d =gcd(cnt, n);
if(d != 1)
return d;
}
return n;
}
int n,x,y;
int a[100005];
int su[1000005];
int idx;
int c[1000005];
void yu(){
for(int i=2;i<=1000000;i++){
if(!c[i])su[++idx]=i;
for(int j=1;j<=idx&&su[j]*i<=1e6;j++){
c[i*su[j]]=1;
if(i%su[j]==0)break;
}
}
}
map<int,int>hh;
map<int,int>op;
map<int,int>yop;
void suan(int now,int f){
while(now>1){
if(mr(now)){
if(f==1)hh[now]++;
else if(f==2)yop[now]++;
else op[now]++;
return;
}
else if(now<=1e4){
for(int i=1;su[i]<=sqrt(now)&&i<=idx;i++){
while(now%su[i]==0){
now/=su[i];
if(f==1)hh[su[i]]++;
else if(f==2)yop[su[i]]++;
else op[su[i]]++;
}
}
if(now>1){
if(f==1)hh[now]++;
else if(f==2)yop[now]++;
else op[now]++;
}
now=1;
break;
}
else{
int xx=pr(now);
if(xx>1e4){
xx=now/xx;
}
for(int i=1;su[i]<=sqrt(xx)&&i<=idx;i++){
while(xx%su[i]==0){
xx/=su[i];
if(f==1)hh[su[i]]++;
else if(f==2)yop[su[i]]++;
else op[su[i]]++;
}
}
if(xx>1){
if(f==1)hh[xx]++;
else if(f==2)yop[xx]++;
else op[xx]++;
}
now/=xx;
}
}
}
map<int,int>ans;
void icealsoheat(){
cin>>n>>x>>y;
hh.clear();
op.clear();
yop.clear();
ans.clear();
for(int i=1;i<=n;i++){
int xx;
cin>>xx;
for(int j=2;j<=xx;j++){
suan(j,1);
// cout<<j<<":::"<<hh[2]<<"+++\n";
}
}
for(int i=2;i<=y;i++){
suan(i,2);
}
suan(x,0);
ans=hh;
int res=1e18;
int yan=1;
// cout<<yan;
// cout<<hh[2]<<"++\n";
// cout<<yop[2]<<"+++\n";
for(auto [i,j]:op){
int now=0;
if(hh.find(i)!=hh.end())now+=hh[i];
int re=yop[i];
res=min((re-now)/j,res);
// cout<<i<<":::"<<re<<":::"<<now<<":::"<<j<<"\n";
}
cout<<res<<"\n";
}
signed main(){
ios::sync_with_stdio(false); //int128不能用快读!!!!!!
cin.tie();
cout.tie();
int _yq;
_yq=1;
cin>>_yq;
yu();
while(_yq--){
icealsoheat();
}
}
//
//⠀⠀⠀ ⠀⢸⣿⣿⣿⠀⣼⣿⣿⣦⡀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀ ⠀⢸⣿⣿⡟⢰⣿⣿⣿⠟⠁
//⠀⠀⠀⠀⠀⠀⠀⢰⣿⠿⢿⣦⣀⠀⠘⠛⠛⠃⠸⠿⠟⣫⣴⣶⣾⡆
//⠀⠀⠀⠀⠀⠀⠀⠸⣿⡀⠀⠉⢿⣦⡀⠀⠀⠀⠀⠀⠀ ⠛⠿⠿⣿⠃
//⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣦⠀⠀⠹⣿⣶⡾⠛⠛⢷⣦⣄⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⠀⠀⠈⠉⣀⡀⠀ ⠀⠙⢿⡇
//⠀⠀⠀⠀⠀⠀⢀⣠⣴⡿⠟⠋⠀⠀⢠⣾⠟⠃⠀⠀⠀⢸⣿⡆
//⠀⠀⠀⢀⣠⣶⡿⠛⠉⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⢸⣿⠇
//⢀⣠⣾⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⢀⣼⣧⣀⠀⠀⠀⢀⣼⠇
//⠈⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⡿⠋⠙⠛⠛⠛⠛⠛⠁
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣾⡿⠋⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⢾⠿⠋⠀
//
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 12032kb
input:
2 3 10 10 2 3 4 2 2 10 1 1
output:
2 8
result:
ok 2 number(s): "2 8"
Test #2:
score: -100
Time Limit Exceeded
input:
8 929 98210021061137 164832982985885580 43576998167336 157303878397705 212661169553039 169068044677212 17733912750082 101059786177542 56528418806042 170741049344189 128297164019222 208810463591190 96264177952672 70816863413347 116985928070432 56330014332760 10006522486360 110959002803542 15298525649...