# A*B Problem

【题目描述】

【输入格式】

【输出格式】

【样例输入】
6
【样例输出】
185 1110
【分析】

(a*b) mod n=(a mod n)×(b mod n)
10^k mod n=(…(((10 mod n)×10) mod n)×10…) mod 10

var
i,n,k,len,r,tmpf,tmpl:longint;
flag:boolean;
long,father:array[0..10000]of longint;
begin
if n=1 then begin write(1,' ',1);halt; end;
fillchar(father,sizeof(father),0);
fillchar(long,sizeof(long),0);
long[1]:=1;
r:=1;
len:=1;
while long[0]=0 do begin
r:=r*10 mod n;
inc(len);
for i:=0 to n-1 do
if (i=0) or (long[i]>0) and (long[i]<len) then begin
k:=i+r;
if k>=n then k:=k-n;
if long[k]=0 then begin
long[k]:=len;
father[k]:=i;
end;
end;
end;
k:=father[0];
tmpf:=k;
tmpl:=len;
father[0]:=-1;
long[0]:=0;
r:=0;
flag:=true;
while k>=0 do begin
r:=r*10+1;
if r div n>0 then begin
write(r div n);
flag:=false;
end;
if (r div n=0)and(flag=false) then write(0);
r:=r mod n;
for i:=len-1 downto long[k]+1 do begin
r:=r*10;
if r div n>0 then begin
write(r div n);
flag:=false;
end;
if (r div n=0)and(flag=false) then write(0);
r:=r mod n;
end;
len:=long[k];
k:=father[k];
end;
write(' ');
k:=tmpf;
len:=tmpl;
father[0]:=-1;
long[0]:=0;
while k>=0 do begin
write(1);
for i:=len-1 downto long[k]+1 do write(0);
len:=long[k];
k:=father[k];
end;
end.

#### 分治算法之大整数相乘问题

2016-10-22 19:18:56

#### 练习三 Problem A

2016-05-16 17:55:32

#### 高精度——A*B Problem

2017-02-10 20:14:28

#### A × B problem

2015-06-19 13:17:05

#### 被玩坏的题目——A+B Problem

2016-07-18 09:36:28

#### 1 A+B Problem

2016-08-26 14:47:06

#### 2016 acm香港网络赛 A题. A+B Problem

2016-09-20 10:13:24

#### 1.A+B Problem

2016-06-29 14:56:33

#### 1:A+B Problem

2014-07-02 17:27:34

#### 1：A+B Problem

2013-03-29 08:51:59