acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 《超时》

    #include<iostream> #include<cmath> #include<cstring> using namespace std; const int maxn=30005; int n,m1,m2,minn=1e9; int prime[maxn]={0}; bool flag=false,here; int pipe_prime[maxn]; int cell_prime[maxn]; int sum_prime=0,cell; bool pr(int k){ for(int i=2;i*i<=k;i++){ if(k%i==0)return false; } return true; } int main(){ cin>>n; cin>>m1>>m2; for(int i=2;i<=maxn;i++){ if(pr(i)){ sum_prime++; prime[sum_prime]=i; } } int idx=1; while(m1!=1){ if(m1%prime[idx]==0) while(m1%prime[idx]==0){ pipe_prime[idx]+=m2; m1/=prime[idx]; } idx++; } for(int i=1;i<=n;i++){ cin>>cell; int j=1; int now=0; here=true; memset(cell_prime,0,sizeof(cell_prime)); while(j<=sum_prime){ if(cell%prime[j]==0){ while(cell%prime[j]==0){ cell_prime[j]; cell/=prime[j]; } } j; } for(j=1;j<=sum_prime;j++){ if(pipe_prime[j]!=0&&cell_prime[j]==0)here=false; if(pipe_prime[j]!=0&&cell_prime[j]!=0){ if(pipe_prime[j]%cell_prime[j]==0) now=max(now,pipe_prime[j]/cell_prime[j]); else now=max(now,pipe_prime[j]/cell_prime[j]+1); } } if(here){ flag=true; if(now<minn)minn=now; } } if(flag)cout<<minn; else cout<<-1; }

    userId_undefined

    130****2333

    倔强青铜
    7阅读
    0回复
    0点赞
首页