比赛 20140711B班小测 评测结果 AAAAAAAAAAATTT
题目名称 残酷的数学老师 最终得分 78
用户昵称 筽邝 运行时间 3.160 s
代码语言 Pascal 内存使用 0.24 MiB
提交时间 2014-07-11 15:45:35
显示代码纯文本
program cojs934;
const
  maxn=15010;
type
  atype=array[1..maxn]of longint;
var
  y,t:atype;
  lent,leny,n,p:longint;

procedure mul(var a,b:atype;var lena,lenb:longint);
var
  c:atype;
  i,j,k,m,lenc:longint;
begin
  fillchar(c,sizeof(c),0);
  for i:=1 to lena do
  for j:=1 to lenb do
  begin
    k:=i+j-1;
    inc(c[k],a[i]*b[j]);
	m:=c[k] div 10;
	while m>0 do
	begin
	  c[k]:=c[k] mod 10;
	  inc(k);
	  inc(c[k],m);
	  m:=c[k] div 10;
	end;
  end;
  lenc:=lena+lenb;
  while (c[lenc]=0)and(lenc>1) do dec(lenc);
  lena:=lenc;
  a:=c;
end;

procedure ksm(p:longint);
begin
  while p<>0 do
  begin
    if p and 1=1 then mul(t,y,lent,leny);
	mul(y,y,leny,leny);
	p:=p shr 1;
  end;
end;

procedure print;
var
  i,count:longint;
begin
  count:=0;
  while (t[lent]=0)and(lent>1) do dec(lent);
  for i:=lent downto 1 do
  begin
    inc(count);
	write(t[i]);
	if count mod 70=0 then writeln;
  end;
end;

begin
assign(input,'cruel1.in');reset(input);
assign(output,'cruel1.out');rewrite(output);

  readln(n,p);
  t[1]:=1; lent:=1;
  while n<>0 do
  begin
    inc(leny);
	y[leny]:=n mod 10;
	n:=n div 10;
  end;
  ksm(p);
  print;

close(input);close(output);
end.