标签:show tar closed 除法 质因数 view close lan play
我们求的就是(x^k)|(m1^m2) k的最小值;
先给m1分解质因数,再给每个细胞分解;
如果m1有的质因数,细胞没有就跳过;
否则就记录答案;
注意整数除法下取整的原则;
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int maxn=30010; 6 int n,m1,m2; 7 int pre_p[maxn],m_p[maxn],num,cell_p[maxn];; 8 bool vis[maxn]; 9 10 void pre_pare() 11 { 12 for(int i=2;i<=30000;i++) 13 { 14 if(!vis[i]) 15 { 16 pre_p[++num]=i; 17 if(m1%i==0) 18 { 19 while(m1%i==0&&m1) 20 { 21 m_p[i]+=m2; 22 m1/=i; 23 } 24 } 25 } 26 for(int j=1;j<=num;j++) 27 { 28 if(pre_p[j]*i>30000) break; 29 vis[pre_p[j]*i]=1; 30 } 31 } 32 } 33 34 void fuck_p(int x) 35 { 36 for(int j=1;j<=num;j++) 37 { 38 while(x%pre_p[j]==0&&x) 39 { 40 cell_p[pre_p[j]]++; 41 x/=pre_p[j]; 42 } 43 } 44 } 45 46 47 int flag; 48 int ans=2147483647,sum; 49 void check() 50 { 51 sum=0; 52 for(int j=1;j<=num;j++) 53 { 54 if(m_p[pre_p[j]]&&!cell_p[pre_p[j]]) {flag=1;return ;} 55 if(m_p[pre_p[j]]) 56 { 57 if(!(m_p[pre_p[j]]%cell_p[pre_p[j]])) sum=max(sum,m_p[pre_p[j]]/cell_p[pre_p[j]]); 58 else sum=max(sum,m_p[pre_p[j]]/cell_p[pre_p[j]]+1); 59 } 60 } 61 } 62 int main() 63 { 64 scanf("%d%d%d",&n,&m1,&m2); 65 pre_pare(); 66 for(int i=1;i<=n;i++) 67 { 68 flag=0; 69 memset(cell_p,0,sizeof(cell_p)); 70 int x; 71 scanf("%d",&x); 72 fuck_p(x); 73 check(); 74 if(flag) continue; 75 ans=min(ans,sum); 76 } 77 printf("%d",ans==2147483647?-1:ans); 78 return 0; 79 }
标签:show tar closed 除法 质因数 view close lan play
原文地址:https://www.cnblogs.com/WHFF521/p/11650107.html