Problem 2 西行寺幽幽子(spring.cpp/c/pas)
题目描述 在幻想乡,西行寺幽幽子是以贪吃闻名的亡灵。不过幽幽子可不是只会吃,至少她还管理着
亡灵界。话说在幽幽子居住的白玉楼有一颗常年不开花的樱树——西行妖。幽幽子决定去收集
人间的春度,聚集起来让西行妖开花。很快,作为幽幽子家园艺师的魂魄妖梦收集到了 M 个
单位的春度。并且在这段时间里,幽幽子计算出要让西行妖开出一朵花需要 N 个单位的春度。
现在幽幽子想要知道,使用所有的春度,能够让西行妖开出多少朵花。
输入格式 第 1 行:一个正整数 M
第 2 行:一个正整数 N
N,M 的位数不超过L,L 的范围在题目后面给出
输出格式 第 1 行:一个整数ans,表示能开出花的朵数
输入样例 73861758
12471
输出样例 5922
数据范围 对于 60%的数据:L <= 2,000 且 ans <= 2,000
对于 100%的数据:L <= 20,000 且 ans <= 2,000,000,000
const md=10000;
max=2000000000;
type arr=array[0..20000] of int64;
var n,m,now:arr;
s:ansistring;
i,j,k,sum:longint;
l,r,mid:int64;//fuck
procedure change(var a:arr);
var i,len:longint;
s0:string;
begin
len:=length(s);
{for i:=1 to len do
a[i]:=ord(s[len-i+1])-ord('0');
a[0]:=len;}
while length(s)>=4 do
begin
s0:=copy(s,length(s)-3,4);
inc(a[0]); val(s0,a[a[0]]);
delete(s,length(s)-3,4);
end;
if s<>'' then
begin
inc(a[0]); val(s,a[a[0]]);
end;
end;
procedure cheng;
var i:longint;
begin
now:=n; now[1]:=now[1]*mid;
for i:=2 to now[0] do
begin
now[i]:=now[i]*mid+now[i-1] div md;
now[i-1]:=now[i-1] mod md;
end;
while now[now[0]]>md do
begin
inc(now[0]); now[now[0]]:=now[now[0]-1] div md;
now[now[0]-1]:=now[now[0]-1] mod md;
end;
end;
function ok:boolean;
var i:longint;
begin
cheng;
if now[0]>m[0] then exit(false);
if m[0]>now[0] then exit(true);
for i:=now[0] downto 1 do
if now[i]>m[i] then exit(false)
else if now[i]<m[i] then exit(true);
exit(true);
end;
begin
assign(input,'spring.in'); assign(output,'spring.out');
reset(input); rewrite(output);
readln(s); change(m);
readln(s); change(n);
l:=0; r:=max;
{mid:=5984; cheng;}
while r-l>1 do
begin
mid:=(r+l) div 2;
if ok then l:=mid else r:=mid;//fuck
end;
writeln(l);
close(input); close(output);
end.