必背代码
非常有用的一些代码
//求阶乘 function fac(n:longint):longint; var i:longint; begin fac:=1; for i:=2 to n do fac:=fac*i; end; //素数判断 function prime(a:longint):boolean; var i:longint; begin if a<2 then exit(false); for i:=2 to trunc(sqrt(a)) do if a mod i=0 then exit(false); exit(true); end; //筛选法求素数 var i,j,n:longint; prime:array[1..1000] of boolean; begin prime[1]:=FALSE; for i:=1 to 1000 do prime[i]:=true; for i:=2 to trunc(sqrt(1000)) do if prime[i] then for j:=2 to 1000 div i do prime[i*j]:=false; end. //最大公约、最小公倍 function GCD(a,b:longint):longint; begin if a mod b=0 then exit(b) else exit(GCD(b,a mod b)); end; function LCM(a,b:longint):longint; begin exit(a*b div GCD(a,b)); end; //进制转换(<10) function conv(a,n:longint):string; begin conv:=''; while a>0 do begin conv:=chr((a mod n)+48)+conv; a:=a div n; end; end; //进制转换(>=10) const r:array[0..19]of char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'); function conv(a,n:longint):string; begin conv:=''; while a>0 do begin conv:=r[a mod n]+conv; a:=a div n; end; end; //回文判断(字符串版) function PLD(s:string):boolean; var len,i:longint; begin len:=length(s); for i:=1 to len div 2 do if s[i]<>s[len+1-i] then exit(false); exit(true); end; //回文判断(数值版) function REV(a:longint):longint; begin REV:=0; while a>0 do begin REV:=REV*10+a mod 10; a:=a div 10; end; end; function PLD(a:longint):boolean; begin exit(a=REV(a)); end; //快速排序(最终版) procedure Qsort(l,r:longint); var mid,i,j,t:longint; begin i:=l; j:=r; mid:=a[(l+r) div 2]; repeat while a[i]<mid do inc(i); while a[j]>mid do dec(j); if i<=j then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); end; until i>j; if i<r then Qsort(i,r); if l<j then Qsort(l,j); end;
//高精度乘法(m的n次方)
const mx=1000;
var a:array[1..mx]of longint;
i,j,m,n:longint;
procedure multi(n:longint);
var i:longint;
begin
for i:=1 to mx do a[i]:=a[i]*n;
for i:=1 to mx-1 do
begin
inc(a[i+1],a[i] div 10);
a[i]:=a[i] mod 10;
end;
end;
procedure print;
var i,j:longint;
begin
for i:=mx downto 1 do
if a[i]>0 then break;
for j:=i downto 1 do write(a[j]);
writeln;
end;
begin
readln(m,n);
a[1]:=1;
for i:=1 to n do multi(m);
print;
end.