为什么float point exception
查看原帖
为什么float point exception
315205
Kniqht楼主2022/9/5 21:38

rt,有没有大佬帮忙看看,谢谢!

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,Inf=0x3f3f3f3f;
int n,a[N],m1,m2;
int primes[N],p[N],pcnt[N],now,cnt;
bool st[N]; 
void init(int n){
    for(int i=2;i<=n;i++){
        if(!st[i]) primes[cnt++]=i;
        for(int j=0;primes[j]*i<=n;j++){
            st[primes[j]*i]=true;
            if(i%primes[j]==0) break; 
        }
    }
}
int main(){
    init(N-10);
    scanf("%d%d%d",&n,&m1,&m2);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int last=-1;
    for(int i=0;i<cnt&&primes[i]<=m1;i++){
        int np=primes[i];
        while(m1%np==0){
            m1/=np;
            if(last==np)
                pcnt[now]++;
            else{
                last=np;
                p[++now]=np;
                pcnt[now]=1;
            }
        }
    }
    for(int i=1;i<=now;i++){
        pcnt[i]*=m2;    
        // cout<<pcnt[i]<<endl;
    }
    int ans=Inf,ansp=-1;
    for(int i=1;i<=n;i++){
        int maxx=-Inf,t=a[i];
        //*****************************************下面这一块寄了!
        for(int j=1;j<=cnt;j++){
            int tt=0;
            if(p[j]>t||t==1||t%p[j]!=0){
                maxx=-Inf;
                break;
            }
            while(t%p[j]==0){
                t/=p[j];
                tt++;
            }
            if(tt>=pcnt[j]) maxx=max(maxx,1);
            else maxx=max(maxx,(pcnt[j]%tt==0?pcnt[j]/tt:pcnt[j]/tt+1));
        }//就是这一段寄了
        if(maxx!=-Inf) ans=min(ans,maxx);
    }
    if(ans==Inf){
        printf("-1");
        return 0;
    }
    printf("%d",ans);
	return 0;
}
2022/9/5 21:38
加载中...