vijos p1042 捕风捉影

来源:百度知道 编辑:UC知道 时间:2024/06/28 10:51:11
这题怎么做不超时(不打表)

以下是我的程序
var m,n,i:longint;
function huiwen(i:longint):boolean;
var str1:string;
l,j:integer;
begin
huiwen:=false;
str(i,str1);
l:=length(str1);
if l mod 2=0 then begin
for j:=1 to l div 2 do
if ord(str1[j])=ord(str1[l+1-j]) then huiwen:=true
else begin huiwen:=false; exit; end;
end;
if l mod 2<>0 then begin
for j:=1 to (l-1) div 2 do
if ord(str1[j])=ord(str1[l+1-j]) then huiwen:=true
else begin huiwen:=false; exit; end;
end;
if l=1 then huiwen:=true;
end;
function sushu(i:longint):boolean;
var j:longint;
begin
sushu:=true;
for j:=2 to trunc(sqrt(i)) do
if (i mod j=0) and (i<>2) then begin sushu:=false; exit; end;
if i=

看看我的题解:
不打表,不优化,直接过,数据弱:
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 0ms
├ 测试数据 06:答案正确... 0ms
├ 测试数据 07:答案正确... 0ms
├ 测试数据 08:答案正确... 0ms
├ 测试数据 09:答案正确... 0ms
├ 测试数据 10:答案正确... 0ms
-------------------------
Accepted 有效得分:100 有效耗时:0ms

var
a, b, count, f, i, l, n : longint;
num : int64;
temp : string;
ans : array[1 .. 30000] of int64;

function prime(x : int64) : boolean;
var
i : longint;
begin
if x = 1 then exit(false);
for i := 2 to trunc(sqrt(x)) do
if x mod i = 0 then exit(false);
prime := true;
end;

procedure swap(var a, b : int64);
var
temp : int64;
begin
temp := a;
a := b;
b := temp;
end;

procedure sort(l, r : longint);
var
i, j, mid : longint;
b