NOIP2009T3 细胞分裂

本文探讨了如何通过编程和算法解决一个特定的数学问题,包括定义变量、使用函数、循环和条件语句来实现解决方案。

 

 

var
    m1,m2,m,tot:longint;
    b,t:array[1..6] of longint;
    n,i,j,s,c,ans,ans2,ans3:longint;
    ab:boolean;
function ceil(x:real):longint;
begin
    if frac(x)>1e-8 then exit(trunc(x)+1);
    exit(trunc(x));
end;

function MAX(a,b:longint):longint;
begin
    if a>b then exit(a) else exit(b);
end;

function MIN(a,b:longint):longint;
begin
    if a<b then exit(a) else exit(b);
end;

begin
    assign(input,'cell.in'); reset(input);
    assign(output,'cell.out'); rewrite(output);
    readln(n,m1,m2);
    tot:=0; m:=m1;
    for i:=2 to m do
    begin
        if m1 mod i=0 then
        begin
            inc(tot); b[tot]:=i;
            while m1 mod i=0 do begin m1:=m1 div i; inc(t[tot]); end;
        end;
    end;
    for i:=1 to tot do t[i]:=t[i]*m2;

    ans:=maxlongint;
    for i:=1 to n do
    begin
        read(s); ans2:=0;
        for j:=1 to tot do
        begin
            c:=0;
            while s mod b[j]=0 do begin s:=s div b[j]; inc(c); end;
            if c=0 then begin ans2:=maxlongint; break; end
            else begin ans3:=ceil(t[j]/c);  ans2:=MAX(ans2,ans3); end;
        end;
        ans:=MIN(ans,ans2);
    end;
    if ans=maxlongint then ans:=-1;
    writeln(ans);
    close(input); close(output);
end.

 

转载于:https://www.cnblogs.com/qilinart/articles/3388891.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值