题解

191 条题解

  • 0
    @ 2009-09-15 18:50:04

    program da;

    var

    a:array[1..100000]of longint;

    s:string;

    i,j,k,l,m,n,o,p:longint;

    f:boolean;

    begin

    read(m,n);

    if (m=5)then writeln('5');

    if (m=7)then writeln('7');

    if (m=11)then writeln('11');

    for i:=10 to 99 do begin    f:=true;

    k:=i;

    str(k,s);

    s:=s+s[1];

    val(s,k,j);

    for j:=2 to trunc(sqrt(k)) do

       if k mod j =0 then f:=false;

    if (f)and(m=k) then writeln(k);

    end;

    for i:=100 to 999 do begin    f:=true;

    str(i,s);

    s:=s+s[2];

    s:=s+s[1];

    val(s,k,j);

    for j:=2 to trunc(sqrt(k)) do

       if k mod j =0 then f:=false;

    if (f)and(m=k) then writeln(k);

    end;

    for i:=1000 to 9999 do begin    f:=true;

    str(i,s);

    s:=s+s[3];

    s:=s+s[2];

    s:=s+s[1];

    val(s,k,j);

    for j:=2 to trunc(sqrt(k)) do

       if k mod j =0 then f:=false;

    if (f)and(m=k) then writeln(k);

    end;

    end.

  • 0
    @ 2009-09-15 13:13:24

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 113ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:113ms

  • 0
    @ 2009-09-14 23:03:36

    好吧 我承认我用了一个本世纪最强悍的剪枝---|---|--

    if n>9989899 then n:=9989899...........

    ORZ提出此剪枝的神牛

  • 0
    @ 2009-09-08 18:56:09

    e,我曾经试着不打表而直接判断,但是。。第十个点超级变态!!最优了也没有办法AC,结果就90分。看来也只有回文数用打表了。。

  • 0
    @ 2009-09-06 21:00:44

    program da;

    var

    a:array[1..100000]of longint;

    s:string;

    i,j,k,l,m,n,o,p:longint;

    f:boolean;

    begin

    read(m,n);

    if (m=5)then writeln('5');

    if (m=7)then writeln('7');

    if (m=11)then writeln('11');

    for i:=10 to 99 do begin f:=true;

    k:=i;

    str(k,s);

    s:=s+s[1];

    val(s,k,j);

    for j:=2 to trunc(sqrt(k)) do

    if k mod j =0 then f:=false;

    if (f)and(m=k) then writeln(k);

    end;

    for i:=100 to 999 do begin f:=true;

    str(i,s);

    s:=s+s[2];

    s:=s+s[1];

    val(s,k,j);

    for j:=2 to trunc(sqrt(k)) do

    if k mod j =0 then f:=false;

    if (f)and(m=k) then writeln(k);

    end;

    for i:=1000 to 9999 do begin f:=true;

    str(i,s);

    s:=s+s[3];

    s:=s+s[2];

    s:=s+s[1];

    val(s,k,j);

    for j:=2 to trunc(sqrt(k)) do

    if k mod j =0 then f:=false;

    if (f)and(m=k) then writeln(k);

    end;

    end.

  • 0
    @ 2009-09-06 13:10:30

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:运行时错误...|错误号: 207

    ├ 测试数据 04:运行超时|无输出...

    ├ 测试数据 05:运行时错误...|错误号: 207

    ├ 测试数据 06:运行超时|无输出...

    ├ 测试数据 07:运行超时|无输出...

    ├ 测试数据 08:运行超时|无输出...

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:运行超时|无输出...

    ---|---|---|---|---|---|---|---|-

    Unaccepted 有效得分:30 有效耗时:0ms

    呜呜,怎么会这样呢?

  • 0
    @ 2009-09-04 23:52:10

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    没用数组存储,直接构造

    建议先用筛选法弄出10000以内素数表

    #include

    #include

    #include

    int a,b;

    int su[10000],top=-1;

    int fang[20]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

    void set()

    {

    int i,j,x[10000]={0};

    for(i=2;i

  • 0
    @ 2009-08-30 22:05:59

    var i,m,n,a,l:longint;

    s:string;

    function pd(c:longint):boolean;

    var i:longint;

    begin

    pd:=true;

    for i:=2 to trunc(sqrt(c)) do

    if c mod i=0 then

    begin

    pd:=false;

    exit;

    end;

    end;

    begin

    readln(m,n);

    if n>9989899 then n:=9989899;

    for i:=m to n do

    begin

    if (i div 30) and (i div 50) and odd(i) then

    begin

    str(i,s);

    m:=length(s);

    l:=m div 2;

    for n:=1 to (m div 2) do

    if s[n]=s[m-n+1] then dec(l);

    if l=0 then val(s,a);

    if (l=0) and pd(a) then

    begin

    inc(a);

    writeln(s);

    end;

    end;

    end;

    end.

  • 0
    @ 2009-08-28 22:35:58

    PS:打表~~~~~⊙﹏⊙b汗(打表还干嘛做程序啊~~~)

    这是C语言最朴素的写法,速度也有保证。

    #include

    long hw(long number)/*交换数据顺序,修改一下可直接判断回文数,不想改了~~~~~*/

    {

    long a=0,b=0;

    while(number!=0)

    // {

    b=number%10;

    number=number/10;

    a=a*10+b;

    }

    number=a;

    return number;

    }

    long ss(long n)/*判断素数*/

    {

    int i;

    for(i=2;i*in)return 1;

    }

    int main()

    {

    long m,n,i,j;

    scanf("%ld %ld",&m,&n);

    if(n>9989899)n=9989899;/*经旧程序的出的1000000000内的最大数,加速加速~~~*/

    for(i=m;i

  • 0
    @ 2009-08-28 12:10:52

    用程序编程序!!

    打表万岁!!

  • 0
    @ 2009-08-22 11:09:34

    {重要的一条:当某个数有偶数个数位时,绝对不能使质数和回文2个条件同时满足(除了11) ,所以不需要枚举偶数个数位的情况,否则超时}

    program ex;

    var i,j,count,m,n:longint;

    a:array[1..1000000]of longint;

    function check(a:longint):boolean;

    var i,j:longint;

    begin

    for i:=2 to trunc(sqrt(a)) do

    if (a mod i = 0) then exit(false);

    exit(true);

    end;

    procedure doit;

    var i,j,k,l,temp:longint;

    begin

    count:=0;

    for i:=2 to 9 do

    if check(i) then

    begin

    inc(count);

    a[count]:=i;

    end;

    inc(count);

    a[count]:=11;

    for i:=1 to 9 do

    for j:=0 to 9 do

    begin

    temp:=101*i+10*j;

    if check(temp) then

    begin

    inc(count);

    a[count]:=temp;

    end;

    end;

    for i:=1 to 9 do

    for j:=0 to 9 do

    for k:=0 to 9 do

    begin

    temp:=10001*i+1010*j+100*k;

    if check(temp) then

    begin

    inc(count);

    a[count]:=temp;

    end;

    end;

    for i:=1 to 9 do

    for j:=0 to 9 do

    for k:=0 to 9 do

    for l:=0 to 9 do

    begin

    temp:=1000001*i+100010*j+10100*k+1000*l;

    if check(temp) then

    begin

    inc(count);

    a[count]:=temp;

    end;

    end;

    end;

    procedure print;

    var t:longint;

    begin

    t:=1;

    while (t

  • 0
    @ 2009-08-20 10:41:43

    首先声明:打表在此处绝不是好方法。

    我的方法是构造回文数:

    1.判断n的位数(用字符串),因为我们通过推导可以知道,一个n位数可以构造出一个2n或2n-1位数,例如: 13-->131 或 1331;

    2.判断所得回文数是否为素数且属于[m,n],如果是,那么加入数组;

    3.得出所有数据后,用快速排序排好顺序;

    4.输出;

    程序代码:

    program su_he(input,output);

    const

    mx=2000;

    var

    la,lb,l:integer;

    i,j,k,o,p:longint;

    m,n:longint;

    a,b,c,d:string;

    e:array[1..mx]of longint;

    function check(x:longint):boolean;

    var

    i,j:longint;

    begin

    check:=true;

    for i:=2 to trunc(sqrt(x)) do

    if x mod i=0 then check:=false;

    end;

    procedure qsort(head,tail:longint);

    var

    i,j,x:longint;

    begin

    i:=head;

    j:=tail;

    x:=e[head];

    while i

  • 0
    @ 2009-08-20 10:40:51

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 556ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:556ms

    var a,b,c,d:string;

    la,lb,i,j,k,l,p,x,y,t,e,g,h,o:longint;

    s:array[1..1000]of longint;

    procedure qsort(head,tail:longint);

    var

    i,j,x,r:longint;

    begin

    i:=head;

    j:=tail;

    x:=s[i];

    while i

  • 0
    @ 2009-08-19 11:25:38

    4次才AC 唉 水平还不够啊

    对特殊情况要考虑 素数要预处理 才能0ms (打表可不行哦)

  • 0
    @ 2009-08-15 20:17:53

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 259ms

    ├ 测试数据 08:答案正确... 197ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 275ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:731ms

    var s:string;

    m,n,i,j,k,l,r,t:longint;

    procedure sushu(x:longint);

    var i:integer;

    begin

    for i:=2 to trunc(sqrt(x)) do

    if x mod i=0 then

    begin

    k:=1;

    break;

    end;

    end;

    begin

    readln(n,m);

    i:=n;

    if i mod 2=0 then i:=i+1;

    i:=i-2;

    while (i12) and (i1000) and (i100000) and (i10000000 then break;

    if i=10 then continue;

    if i=11 then

    begin

    writeln('11');

    continue;

    end;

    str(i,s);

    l:=length(s);

    r:=l div 2;

    k:=0;

    if r>=1 then

    for j:=1 to r do

    begin

    if s[j]s[l-j+1] then

    begin

    k:=1;

    break;

    end;

    end;

    if k=1 then continue;

    sushu(i);

    if k=1 then continue;

    writeln(i);

    end;

    end.

  • 0
    @ 2009-08-14 10:22:22

    const

    c:array[1..4]of integer=(1,3,7,9);

    var

    a:array[1..1300]of longint;

    k,j,s:integer;

    m,n:longint;

    nn:longint;

    procedure search(i:integer);

    var

    t,p,x:integer;

    b:boolean;

    begin

    if i>s then

    begin

    t:=nn;x:=nn div 10;

    for j:=1 to s-1 do

    begin

    nn:=nn*10;

    nn:=nn+x mod 10;

    x:=x div 10;

    end;

    if (nn>=m)and(nn

  • 0
    @ 2009-08-12 22:03:17

    WA了我4次……AC

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    真正的zero ms狂秒!!!

    var ans:array[1..1000]of longint;

    i,tn,temp,a,b,c,d,n,m:longint;

    bo:array[1..10000] of boolean;

    zs:array[1..10000] of longint;

    j,k,t:longint;

    procedure hw;

    begin

    if (c=0)and(d=0)then

    begin

    temp:=b*100+a*10+b;

    end

    else if (d=0)then

    begin

    temp:=c*10000+b*1000+a*100+b*10+c;

    end

    else

    begin

    temp:=d*1000000+c*100000+b*10000+a*1000+b*100+c*10+d;

    end;

    end;

    procedure get_zs;

    begin

    for i:= 2 to 10000 do bo[i]:=true;

    k:=0;bo[1]:=false;

    for i:= 2 to 10000 do

    if bo[i] then

    begin

    inc(k);

    j:=i*2;

    zs[k]:=i;

    while (j

  • 0
    @ 2009-08-12 17:43:08

    感谢大侠们教会我如何疯狂打表 天哪 全都 0ms!!

  • 0
    @ 2009-08-11 20:40:35

    不用筛选~~直接判断

    生成回文数

    procedure zuo(s:string);

    var k:longint;

    begin

    if length(s)>8 then exit;

    val(s,k);

    if k>m then exit;

    if (k>=n)and(k

  • 0
    @ 2009-08-11 17:02:52

    第十个点超时,郁闷

    program ex28;

    var i,m,n:longint;

    function sushu(k:longint):boolean;

    var i,j:longint;

    begin

    sushu:=true;

    for i:=2 to round(sqrt(k)) do

    if k mod i=0 then sushu:=false;

    end;

    procedure pd(b:longint);

    var letter:string;

    i,j:word;

    begin

    str(b,letter);

    i:=length(letter);

    j:=1;

    while (j=i)and(sushu(b)=true) then writeln(b);

    end;

    begin

    readln(m,n);

    for i:=m to n do pd(i);

    readln;

    end.

信息

ID
1042
难度
7
分类
搜索 | 搜索与剪枝 点击显示
标签
(无)
递交数
6585
已通过
1516
通过率
23%
被复制
13
上传者