14 条题解
-
1aph。 (chenqianrong) LV 10 @ 2021-08-21 11:14:58
#include<bits/stdc++.h> using namespace std; int n,m1,m2,minx,gcdd,m,s,q,t,flag,tot,ans,tots,totq; int S[10001]; int read() { char ch=getchar(); int a=0,x=1; while(ch<'0' || ch>'9') { if(ch=='-') x=-x; ch=getchar(); } while(ch>='0' && ch<='9') { a=(a<<3)+(a<<1)+(ch-'0'); ch=getchar(); } return a*x; } int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } int main() { n=read(); m1=read(); m2=read(); minx=1e9; if(m1==1) { cout<<0; return 0; } for(int i=1;i<=n;i++) S[i]=read(); for(int i=1; i<=n; i++) { tot=0; m=m1; s=S[i]; flag=1; t=0; while(m!=1) { gcdd=gcd(m,s); if(gcdd==1){ flag=0; break; } m/=gcdd; q=s/gcdd; s=gcdd; t++; } if(flag) { int gc=gcd(q,s); if(gc!=1&&gc!=s) { totq=0;tots=0; while(q%gc==0) { totq++; q/=gc; } while(s%gc==0) { tots++; s/=gc; } if((t*m2*tots+totq*(t-1)*m2)%(tots+totq)==0) ans=(t*m2*tots+totq*(t-1)*m2)/(tots+totq); else ans=(t*m2*tots+totq*(t-1)*m2)/(tots+totq)+1; minx=min(minx,ans); } else { while(q%s==0) { tot++; q/=s; } if((t*m2+tot*(t-1)*m2)%(tot+1)==0) ans=(t*m2+tot*(t-1)*m2)/(tot+1); else ans=(t*m2+tot*(t-1)*m2)/(tot+1)+1; minx=min(minx,ans); } } } if(minx==1e9) cout<<-1; else cout<<minx; return 0; }
-
12017-07-26 11:12:32@
之前没有管1个试管的特判,第一个点错了无数次;
可能是最近学数论,将题目看做求解: s[i]^x ≡0(mod m1^m2) 简直太傻逼了;
提示:本体就是一个唯一分解定理的应用:a|b≡b包括a中所有质因数,且数目大于等于b所有质因数
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<climits>
typedef long long LL;
const LL inf=LLONG_MAX;
inline const void read(LL &a)
{
a=0;
char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')
{
a=a*10+c-'0';
c=getchar();
}
}
bool prime[30001];
LL n,s,ans=inf;//病毒数 分裂数 最优答案
LL m1,m2;//试管数m1^m2
void solve_prime()
{
for(LL i=2;i<=30000;i++)
if(prime[i])
for(LL j=2;j*i<=30000;j++)prime[i*j]=false;
}
LL de[30001],num[30001];
LL des[30001];
void devide_m1()
{
memset(de,0,sizeof(de));
memset(num,0,sizeof(num));
LL a=m1;
for(LL i=2;i<=m1;i++)
{
if(a==1)break;
if(prime[i])
while(!(a%i))
{
de[0]++;
de[de[0]]=i;
num[i]++;
a/=i;
}
}
for(LL i=1;i<=m1;i++)num[i]*=m2;
}
inline const void devide(LL c)
{
LL a=c;
memset(des,0,sizeof(des));
for(LL i=2;i<=m1;i++)
{
if(prime[i])
while(!(a%i))
{
des[i]++;
a/=i;
if(a==1)return ;
}
}
}
inline const LL big(LL a,LL b)
{
if(a>b)return a;
else return b;
}
inline const LL small(LL a,LL b)
{
if(a>b)return b;
else return a;
}
int main()
{
memset(prime,true,sizeof(prime));
prime[0]=prime[1]=false;
solve_prime();
read(n);read(m1);read(m2);
devide_m1();
if(m1==1||m2==0)//特判1
{
printf("%d",0);
return 0;
}
for(LL k=1;k<=n;k++)//求解: s^x ≡0(mod m1^m2)
{
LL ansk=-inf;
read(s);
if(s==1)continue;
devide(s);
for(LL i=1;i<=de[0];i++)
{
if(des[de[i]])
ansk=big(LL(ceil(double(num[de[i]])/double(des[de[i]]))),ansk);
else {ansk=inf;break;}
}
ans=small(ansk,ans);
}
if(ans==inf)printf("%d",-1);
else printf("%lld",ans);
return 0;
} -
02016-12-30 22:24:42@
Is this problem difficult?In fact just prime factors decomposition and extracting.Enumeration of the corresponding prime factors, properties: the basic factors of power remains the same.So we can get the answer.Only six lines of code and deal with details determine prime factors.
-
02016-11-17 12:13:33@
评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 860 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 860 KiB, score = 10 测试数据 #2: Accepted, time = 0 ms, mem = 860 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 860 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 860 KiB, score = 10 测试数据 #5: Accepted, time = 0 ms, mem = 860 KiB, score = 10 测试数据 #6: Accepted, time = 0 ms, mem = 860 KiB, score = 10 测试数据 #7: Accepted, time = 31 ms, mem = 864 KiB, score = 10 测试数据 #8: Accepted, time = 31 ms, mem = 860 KiB, score = 10 测试数据 #9: Accepted, time = 46 ms, mem = 864 KiB, score = 10 Accepted, time = 154 ms, mem = 864 KiB, score = 100 代码 #include <algorithm> #include <cstring> #include <cstdio> #include <cmath> using namespace std; const int INF = 999999999; int n,m1,m2,p[30001],num1[30001],num2[30001]; int main() { //freopen("cell.in","r",stdin); //freopen("cell.out","w",stdout); scanf("%d%d%d",&n,&m1,&m2); p[0] = 0; for (int i = 2;i*i <= m1;i++) if (!(m1%i)) { p[++p[0]] = i; while (!(m1%i)) { m1 /= i; num1[p[0]]++; } } if (m1 != 1) { p[++p[0]] = m1; num1[p[0]] = 1; } for (int i = 1;i <= p[0];i++) num1[i] *= m2; int Min = INF; for (int i = 1,x;i <= n;i++) { memset(num2,0,sizeof(num2)); scanf("%d",&x); bool flag = false; for (int j = 1;j <= p[0];j++) if (x%p[j]) { flag = true; break; } if (flag) continue; for (int j = 1;j <= p[0];j++) while (!(x%p[j])) { num2[j]++; x /= p[j]; } int Max = 0; for (int j = 1;j <= p[0];j++) if (num1[j] > num2[j]) { Max = max(Max,(int)(ceil((double)num1[j]/num2[j])+1e-6)); if (Max > Min) break; } Min = min(Min,Max); } printf("%d",Min == INF ? -1 : Min); return 0; }
-
02016-11-16 22:22:28@
编译成功
Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
Linking foo.exe
56 lines compiled, 0.0 sec, 28272 bytes code, 1268 bytes data
测试数据 #0: Accepted, time = 0 ms, mem = 928 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 928 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 928 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 932 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 932 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 928 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 932 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 928 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 932 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 928 KiB, score = 10
Accepted, time = 15 ms, mem = 932 KiB, score = 100
```
var s,a,b:array[0..10000]of longint;
min,i,j,k,m1,m2,n,t:longint; f:boolean;function doit(n:longint):longint;
var max,m,k,i:longint;
begin
max:=-maxlongint;
for i:=1 to j do
begin
m:=0;
while (n mod a[i]=0) do
begin inc(m);n:=n div a[i]; end;
k:=b[i]div m;
if b[i]mod m<>0 then k:=k+1;
if k>max then max:=k;
end;
doit:=max;
end;procedure prime_main(x:longint);
var i:longint;
begin
i:=2;j:=0;
while (x<>1) do begin
if x mod i=0 then
begin
inc(j);a[j]:=i;
while x mod i=0 do
begin
x:=x div i;
inc(b[j]);
end;
b[j]:=b[j]*m2;
end;
inc(i);end;
end;begin
readln(n);
readln(m1,m2);
for i:=1 to n do read(s[i]);
if (m1=1)or(m2=0) then begin write('0');halt end;
prime_main(m1);
min:=maxlongint;
// for i:=1 to j do for k:=1 to b[i] do writeln(a[i],' ');halt;
for i:=1 to n do
begin
f:=true;
for k:=1 to j do
if (s[i] mod a[k]<>0) then begin f:=false;break;end;
if f then t:=doit(s[i]);
if f and (min>t) then min:=t;
end;if min<>maxlongint then writeln(min) else writeln('-1');
end.``` -
02015-09-18 17:00:20@
给定m1^m2的大数和n个数s[]
求s_i^x mod m1^m2=0最小的x由于m1<=30000,m2<=10000,根本无法直接计算,所以需要通过数学分析得出答案。
如果一个数能够整除另一个数,那么这个数因数分解后一定有另一个数所有的元素,且每个元素个数均大于等于另一个数相同元素的个数。
因此我们可以先对m1进行因数分解,并将对应元素的个数乘以m2。
之后读入每个数,判断该数因数分解后是否有m1中所有的元素。
如果有的话,则计算该细胞最大的分裂次数(即对应m1种元素个数/si中元素个数后向上取整)。
枚举分解每一个给定的数,最后更新答案即可。
因数分解中1比较特殊,要单独判断一下。
var
d,di,zi,z:array[0..10000] of longint;
s,x,m,top,j,i,ans,n,p,q:longint;
procedure fenjie(n:longint);
var i:longint; //分解n 底数在d 指数在z 个数为top
begin
fillchar(d,sizeof(d),false);
fillchar(z,sizeof(z),0);
top:=0;
i:=2;
while n<>1 do
if n mod i=0 then
begin
if (i=d[top]) then inc(z[top]) else
begin
inc(top);
d[top]:=i;
inc(z[top]);
end;
n:=n div i;
end else
begin
inc(i);
if i>trunc(sqrt(n)) then break;
end;
if n<>1 then
begin inc(top); d[top]:=n; inc(z[top]); end;
end;
function pan:boolean; //判断次数分解后是否有m1的所有元素
var o,i,j:longint;
begin
s:=0;
j:=1;
for i:=1 to m do
begin
while (di[i]<>d[j]) do
begin
inc(j);
if j>top+1 then exit(false);
end;
if (zi[i]/z[j])-(zi[i] div z[j])>0 //收尾
then o:=(zi[i] div z[j])+1 else o:=zi[i] div z[j];
if o>s then s:=o; //要满足最大的
end;
exit(true);
end;
begin
read(n);
read(p,q);
if p=1 then begin writeln(0); halt; end; //特判1
fenjie(p);
m:=top; di:=d; zi:=z;
for i:=1 to top do zi[i]:=zi[i]*q;
ans:=123456789;
for j:=1 to n do
begin
read(x);
fenjie(x);
if (pan=true) and (s<ans) then ans:=s; //更新答案
end;
if ans=123456789 then writeln(-1) else writeln(ans);
end. -
02015-08-23 12:34:19@
非常简单的一题,就是分解质因数,记得判断试管数为1
您向题目P1814 - 细胞分裂递交的代码已通过评测!
现将代码发送给您保存:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<queue>
#include<stack>using namespace std;
int pr_[25],L;
int t[25];
int txg[25];int main(){
//freopen("cell.in","r",stdin);
//freopen("cell.ans","w",stdout);
int N,m1,m2,tot,i,j,s,ans=0x7fffffff,ansf;
cin>>N>>m1>>m2;
for(i=2;i*i<=m1;i++){
if(m1%i==0)pr_[++L]=i;
while(m1%i==0){t[L]+=m2;m1/=i;}
}
if(m1-1){pr_[++L]=m1;t[L]=m2;}
for(j=1;j<=N;j++){
scanf("%d",&tot);s=0;ansf=-1;
for(i=1;i<=L;i++){
if(tot%pr_[i]!=0) goto next;
while(tot%pr_[i]==0){++s;tot/=pr_[i];}
ansf=max(ansf,(t[i]-1)/s+1);
}
ans=min(ans,L==0?0:(ansf==-1?ans:ansf));
next:;
}
cout<<(ans==0x7fffffff?-1:ans);
return 0;
}
如果您不需要此项功能,请到https://vijos.org/home/settings关闭,谢谢。
这封邮件由Vijos自动发送,请勿直接回复。 -
02014-10-28 18:59:42@
注意特判试管数为1的情况
-
02014-08-09 12:10:34@
0ms....
Code:
编译成功Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
foo.pas(4,5) Note: Local variable "g" not used
Linking foo.exe
63 lines compiled, 0.3 sec , 28528 bytes code, 1628 bytes data
1 note(s) issued
测试数据 #0: Accepted, time = 0 ms, mem = 844 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 844 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 844 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 848 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 844 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 844 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 844 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 844 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 844 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 844 KiB, score = 10
Accepted, time = 0 ms, mem = 848 KiB, score = 100
代码
type
arr=array[1..30000,1..2] of longint;
var
ans,g,i,k,n,m1,m2,total:longint;
a:arr;
procedure factorization(k:longint;var a:arr;var link:longint);
var
i:longint;
begin
i:=1;
link:=0;
repeat
inc(i);
if k mod i=0 then
begin
inc(link);
a[link,1]:=i;
a[link,2]:=0;
while k mod i=0 do
begin
inc(a[link,2]);
k:=k div i;
end;
end;
until k=1;
end;
procedure main;
var
i,z,max:longint;
begin
max:=-1;
read(k);
for i:=1 to total do
begin
if k mod a[i,1]<>0 then exit;
z:=0;
while k mod a[i,1]=0 do
begin
inc(z);
k:=k div a[i,1];
end;
if (a[i,2]+z-1) div z>max then max:=(a[i,2]+z-1) div z;
end;
if max<ans then ans:=max;
end;
begin
ans:=maxlongint;
readln(n);
readln(m1,m2);
if m1=1 then
begin
writeln(0);
halt;
end;
factorization(m1,a,total);
for i:=1 to total do
a[i,2]:=a[i,2]*m2;
for i:=1 to n do
main;
if ans=maxlongint then writeln(-1)
else writeln(ans);
readln;
readln;
end. -
02014-04-20 12:47:09@
AC370题留恋!
-
02014-01-01 21:38:10@
###
var n,m1,m2,i,j,l,ans,nowans,temp,total:longint;
x,y,s:array[0..30000]of longint;
b:boolean;
procedure FenJieZhiYinShu(n:longint);
begin
i:=1;j:=0;
while n<>1 do
begin
i:=i+1;
if n mod i=0 then
begin
j:=j+1;
x[j]:=i;
y[j]:=0;
while n mod i=0 do
begin
n:=n div i;
y[j]:=y[j]+1;
end;
end;
end;
l:=j;
end;
begin
readln(n);
readln(m1,m2);
for i:=1 to n do read(s[i]);
if(m1=1)or(m2=0)then
begin
writeln(0); exit;
end;
FenJieZhiYinShu(m1);
for i:=1 to l do y[i]:=y[i]*m2;
ans:=maxlongint;
for i:=1 to n do
begin
b:=true; nowans:=0;
for j:=1 to l do
begin
temp:=s[i];
total:=0;
while temp mod x[j]=0 do
begin
temp:=temp div x[j];
total:=total+1;
end;
if total=0 then begin b:=false;break;end;
temp:=y[j]div total;
if y[j]mod total<>0 then temp:=temp+1;
if nowans<temp then nowans:=temp;
end;
if b=false then continue;
if nowans<ans then ans:=nowans;
end;
if ans<>maxlongint then writeln(ans)else writeln(-1);
end. -
02014-01-01 21:36:35@
###Block Code
var c,y:array[0..30001] of longint;
n,m1,m2,z1,z2,t,res,f:longint;
Procedure check(k:longint);
var z1,z2,d,max:longint;
begin
max:=-1;
for z1:=1 to t do
begin
d:=0;
while k mod c[z1]=0 do
begin
inc(d);
k:=k div c[z1];
end;
If d=0 then exit;
z2:=y[z1] div d;
If z2*d<y[z1] then inc(z2);
If z2>=res then exit;
If z2>max then max:=z2;
end;
res:=max;
end;
begin
readln(n); readln(m1,m2);
f:=m1;
for z1:=2 to m1 do
for z2:=2 to m1 div z1 do c[z1*z2]:=1;
z2:=1;
while z2<m1 do
begin
inc(z2);
If (c[z2]=0)and(m1 mod z2=0) then
begin
inc(t); c[t]:=z2;
while m1 mod z2=0 do
begin
inc(y[t]);
m1:=m1 div z2;
end;
end;
end;
res:=maxlongint;
for z1:=1 to t do y[z1]:=y[z1]*m2;
for z1:=1 to n do
begin
read(z2);
check(z2);
end;
If f=1 then writeln(0) else
If res=maxlongint then writeln(-1) else
writeln(res);
end. -
02013-11-05 22:09:48@
评测结果
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 840 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 836 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 836 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 836 KiB, score = 10
测试数据 #4: Accepted, time = 171 ms, mem = 836 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 840 KiB, score = 10
测试数据 #6: Accepted, time = 78 ms, mem = 836 KiB, score = 10
测试数据 #7: Accepted, time = 62 ms, mem = 836 KiB, score = 10
测试数据 #8: Accepted, time = 578 ms, mem = 840 KiB, score = 10
测试数据 #9: Accepted, time = 500 ms, mem = 836 KiB, score = 10
Accepted, time = 1419 ms, mem = 840 KiB, score = 100
代码#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>using namespace std;
int N;
int m1 , m2 , m3;
int a[10000 + 10] , b[30000] , c[30000];
int i , j;
int tem;
int getans;
int maxd , maxe , maxf , tht , tt;int main()
{
while( scanf( "%d" , &N ) != EOF )
{
getans = 0;
maxd = maxe = 0;
maxf = 1000000000;
memset( a , 0 , sizeof( a ) );
memset( b , 0 , sizeof( b ) );
memset( c , 0 , sizeof( c ) );
scanf( "%d %d" , &m1 , &m2 );
m3 = m1;
//cout << m3 << endl;
for( i = 0 ; i < N ; i++ )
scanf( "%d" , &a[i] );
while( m1 % 2 == 0 )
{
//cout << "f\n";
m1 /= 2;
b[2]++;
}
for( i = 3 ; i <= m1 ; i += 2 )
{
while( m1 % i == 0 )
{
//cout << "f\n";
m1 /= i;
b[i]++;
}
if( m1 == 1 )
break;
}
//cout << "f\n";
m1 = m3;
/*for( i = 0 ; i <= m1 ; i++ )
if( b[i] != 0 )
cout << i << " " << b[i] << endl;*/
for( i = 0 ; i <= m1 ; i++ )
{
b[i] *= m2;
maxd = i;
}
for( i = 0 ; i < N ; i++ )
{
memset( c , 0 , sizeof( c ) );
tht = 0;
maxe = 0;
tem = a[i];
while( tem % 2 == 0 )
{
//cout << "f\n";
tem /= 2;
c[2]++;
}
for( j = 3 ; j <= m1 ; j += 2 )
{
while( tem % j == 0 )
{
//cout << "f\n";
tem /= j;
c[j]++;
}
if( tem == 1 )
break;
}
tt = 1;
for( j = 0 ; j <= maxd ; j++ )
{
if( b[j] != 0 && c[j] == 0 )
{
tt = 0;
break;
}
if( b[j] != 0 )
{
//cout << j << " " << b[j] << " " << c[j] << endl;
if( b[j] % c[j] == 0 )
tht = b[j] / c[j];
else
tht = ( int )( b[j] / c[j] ) + 1;
if( tht > maxe )
maxe = tht;
}
}
//cout << maxe << endl;
if( maxe < maxf && tt != 0 )
maxf = maxe;
if( tt != 0 )
getans = 1;
}
if( !getans )
cout << "-1\n";
else
cout << maxf << endl;
}
return 0;
} -
02013-10-05 19:41:14@
var c,y:array[0..30001] of longint;
n,m1,m2,z1,z2,t,res,f:longint;Procedure check(k:longint);
var z1,z2,d,max:longint;
begin
max:=-1;
for z1:=1 to t do
begin
d:=0;
while k mod c[z1]=0 do
begin
inc(d);
k:=k div c[z1];
end;
If d=0 then exit;
z2:=y[z1] div d;
If z2*d<y[z1] then inc(z2);
If z2>=res then exit;
If z2>max then max:=z2;
end;
res:=max;
end;begin
readln(n); readln(m1,m2);
f:=m1;
for z1:=2 to m1 do
for z2:=2 to m1 div z1 do c[z1*z2]:=1;
z2:=1;
while z2<m1 do
begin
inc(z2);
If (c[z2]=0)and(m1 mod z2=0) then
begin
inc(t); c[t]:=z2;
while m1 mod z2=0 do
begin
inc(y[t]);
m1:=m1 div z2;
end;
end;
end;
res:=maxlongint;
for z1:=1 to t do y[z1]:=y[z1]*m2;
for z1:=1 to n do
begin
read(z2);
check(z2);
end;
If f=1 then writeln(0) else
If res=maxlongint then writeln(-1) else
writeln(res);
end.
- 1
信息
- ID
- 1814
- 难度
- 7
- 分类
- (无)
- 标签
- 递交数
- 1412
- 已通过
- 323
- 通过率
- 23%
- 被复制
- 15
- 上传者