首页| 论坛| 消息
主题:悬赏了(200)
回帖:重做了一遍
增加了1000003的倍数的处理
减少了小于7时的判断(本来以为小于7时不能用费马小定理)
var
n,r,t:int64;
procedure power(a,b:int64;var t:int64);
var
i:longint;
begin
for i:=1 to a do
t:=t*n mod b;
end;
begin
read(n);
if n mod 1000003=0
then write(0)
else
if n=2
then write(16)
else
begin
r:=1;
power(n,1000002,r);
t:=1;
power(r,1000003,t);
write(t);
end;
end.
下一楼›:不能用exp ln来算
因为算到n=5时 数据有2084位就算是int64也存不下
‹上一楼:我第一
数据测试到
10000000用时2秒以内
20000000用时不超过3秒

--> 查看全部回帖(33)
«返回主帖