c语言求助大佬,真的受不了这道题了,测试点不对是为什么,打表都不对吗

P1217 [USACO1.5] 回文质数 Prime Palindromes

34zf @ 2023-10-31 01:29:59

#include<stdio.h>
int main()
{
    int a,b,len=1,Q;
    int zhishu(int a);
    scanf("%d%d",&a,&b);
    if(b>=5)printf("5\n");
    if(b>=7)printf("7\n");
    if(b>=11)printf("11\n");
    len=b/10;
    if(b>=3)
    for(int d1=1;d1<=9;d1=d1+2)//长度为三的回文数 
    for(int d2=0;d2<=9;d2++)
    {Q=d1*100+d2*10+d1;
    if(zhishu(Q)&&Q<=b)printf("%d,",Q);
    if(Q>b)return 0;
    }
    if(b>=5)
    for(int d1=1;d1<=9;d1=d1+2)//长度为五的回文数 
    for(int d2=0;d2<=9;d2++)
    for(int d3=0;d3<=9;d3++)
    {Q=d1*10000+d2*1000+d3*100+d2*10+d1;
    if(zhishu(Q)&&Q<=b)printf("%d,",Q);
    if(Q>b)return 0;
    }
    if(b>=7)
    for(int d1=1;d1<=9;d1=d1+2)//长度为七的回文数 
    for(int d2=0;d2<=9;d2++)
    for(int d3=0;d3<=9;d3++)
    for(int d4=0;d4<=9;d4++)
    {Q=d1*1000000+d2*100000+d3*10000+d4*1000+d3*100*d2*10+d1;
    if(zhishu(Q)&&Q<=b)printf("%d,",Q);
    if(Q>b)return 0;
    }    

    return 0;
}
int zhishu(int a)
 {
    for(int i=2;i*i<a;i++)
    {
        if(a%i==0)
        {
            return 0;
        }

     }
     return 1;
 }

by 34zf @ 2023-10-31 01:30:53

我试过了,答案基本是秒出


by 34zf @ 2023-10-31 01:32:14

这是我用上面代码做的打表版,也不对,一个测试点都不对为什么,我打入5 500是一样啊```c

include<stdio.h>

int main() { int n,m,brr[1000]={5,7,11,101,121,131,151,181,191,313,353,373,383,727,757,787,797,919,929,10201,10301,10501,10601,11311,11411,12421,12721,12821,13331,13831,13931,14341,14741,15451,15551,16061,16361,16561,16661,17471,17971,18181,18481,19391,19891,19991,30103,30203,30403,30703,30803,31013,31513,32323,32423,33533,34543,34843,35053,35153,35353,35753,36263,36563,37273,37573,38083,38183,38783,39293,70207,70507,70607,71317,71917,72227,72727,73037,73237,73637,74047,74747,75557,76367,76667,77377,77477,77977,78487,78787,78887,79397,79697,79997,90709,91019,93139,93239,93739,94049,94249,94349,94649,94849,94949,95959,96269,96469,96769,97379,97579,97879,98389,98689,1003001,1008001,1011001,1020001,1021001,1027001,1029001,1033001,1036001,1038001,1039001,1042001,1059001,1062001,1063001,1066001,1069001,1074001,1078001,1084001,1087001,1102001,1108001,1116001,1120001,1122001,1125001,1137001,1144001,1153001,1155001,1159001,1161001,1164001,1168001,1173001,1186001,1188001,1201001,1207001,1201001,1207001,1228001,1231001,1237001,1239001,1242001,1245001,1248001,1269001,1272001,1273001,1276001,1279001,1291001,1293001,1297001,1311001,1312001,1306001,1326001,1330001,1339001,1342001,1347001,1348001,1357001,1371001,1378001,1395001,1396001,1413001,1419001,1414001,1419001,1432001,1435001,1446001,1447001,1449001,1456001,1461001,1462001,1476001,1477001,1491001,1498001,1518001,1528001,1518001,1537001,1545001,1551001,1560001,1564001,1567001,1578001,1579001,1582001,1584001,1591001,1605001,1614001,1620001,1636001,1644001,1605001,1620001,1636001,1648001,1650001,1657001,1668001,1696001,1698001,1699001,1705001,1719001,1729001,1735001,1747001,1749001,1752001,1705001,1719001,1735001,1752001,1768001,1770001,1785001,1789001,1803001,1806001,1810001,1824001,1839001,1855001,1857001,1861001,1803001,1806001,1824001,1839001,1855001,1857001,1861001,1872001,1894001,1896001,1897001,1914001,1917001,1932001,1953001,1962001,1963001,1969001,1920001,1942001,1962001,1963001,1983001,2002001,2004001,2019001,2020001,2023001,2035001,2041001,2053001,2056001,2076001,2077001,3001003,3002003,3007003,3011003,3014003,3025003,3038003,3040003,3049003,3052003,3059003,3067003,3070003,3079003,3086003,3106003,3115003,3122003,3137003,3148003,3152003,3155003,3161003,3164003,3172003,3178003,3184003,3191003,3200003,3205003,3200003,3205003,3217003,3218003,3220003,3229003,3232003,3239003,3245003,3260003,3262003,3275003,3277003,3280003,3284003,3287003,3296003,3298003,3302003,3304003,3313003,3302003,3304003,3313003,3319003,3322003,3329003,3346003,3352003,3353003,3365003,3368003,3379003,3382003,3397003,3406003,3407003,3421003,3403003,3406003,3407003,3421003,3436003,3445003,3449003,3451003,3464003,3470003,3488003,3493003,3535003,3508003,3535003,3551003,3560003,3568003,3569003,3575003,3581003,3593003,3596003,3610003,3613003,3614003,3625003,3638003,3625003,3638003,3649003,3667003,3704003,3730003,3731003,3733003,3736003,3737003,3751003,3704003,3736003,3737003,3751003,3788003,3793003,3794003,3802003,3806003,3821003,3827003,3854003,3857003,3859003,3862003,3802003,3806003,3821003,3827003,3854003,3857003,3859003,3862003,3878003,3880003,3896003,3898003,3910003,3914003,3932003,3935003,3949003,3904003,3905003,3907003,3920003,3922003,3959003,3976003,3977003,3980003,3997003,3998003,4001003,4016003,4019003,4022003,4075003,4076003,4078003,4079003,7017007,7026007,7045007,7048007,7051007,7054007,7059007,7062007,7065007,7068007,7072007,7089007,7093007,7095007,7099007,7111007,7117007,7120007,7122007,7128007,7141007,7149007,7150007}; scanf("%d%d",&n,&m); for(int i=0;brr[i]<m;i++) { printf("%d\n",brr[i]); } return 0; }


by 34zf @ 2023-10-31 01:54:51

不用了大佬们,我发现问题了,有一些小细节打错了,还是不够细心,当然辽,这个帖子也可以给新手一点警告,还是得细心点


|