D:链接 寛神有一堆的幸运数,因为他非常善于学习,只要听到有人用哪个数做幸运数,就会把这个数加到自己的幸运数集合。
直到有一天他听说了波兰数学家乌拉姆的幸运数。它采用与生成素数类似的“筛法”生成。
首先从1开始写出自然数1,2,3,4,5,6,....
1就是第一个幸运数。
我们从2这个数开始。把所有序号能被2整除的项删除,变为:
1 _ 3 _ 5 _ 7 _ 9 ....
把它们缩紧,重新记序,为:
1 3 5 7 9 ....。这时,3为第2个幸运数,然后把所有能被3整除的序号位置的数删去。注意,是序号位置,不是那个数本身能否被3整除!!删除的应该是5,11, 17, ...
此时7为第3个幸运数,然后再删去序号位置能被7整除的(19,39,...)
最后剩下的序列类似:
1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, ...

D题,毫无技术的AC了,如果数据范围大一点,我就不会了
思路:首先暴力打表,发现只有1600个,然后测试一下,发现代码字节大小没超,可以提交,

//#include<bits/stdc++.h>
//using namespace std;
//const int N = 15*1000;
//vector<int> vec;
//bool vis[N];
//int main(){
//    vec.push_back(0);
//    for(int i=0;i<=N;i++) if(i%2) vec.push_back(i);
//    int t = 2;
//    while(1){
//        if(t==vec.size()) break;
//        int len = vec.size()-1;
//        int cha = vec[t];
//        for(len ; len>0 ; len--){
//            if(len%cha==0)
//            vec.erase(vec.begin()+len);
//        }
//        t++;
//    }
//}
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,nn,mm;
    scanf("%d %d",&n,&m);
    nn = n , mm = m;
    int a[1602]={
        0,1,3,7,9,13,15,21,25,31,33,37,43,49,51,63,67,69,73,75,79,87,93,99,105,111,115,127,129,133,135,141,151,159,163,169,171,189,193,195,201,205,211,219,223,231,235,237,241,259,261,267,273,283,285,289,297,303,307,319,321,327,331,339,349,357,361,367,385,391,393,399,409,415,421,427,429,433,451,463,475,477,483,487,489,495,511,517,519,529,535,537,541,553,559,577,579,583,591,601,613,615,619,621,631,639,643,645,651,655,673,679,685,693,699,717,723,727,729,735,739,741,745,769,777,781,787,801,805,819,823,831,841,855,867,873,883,885,895,897,903,925,927,931,933,937,957,961,975,979,981,991,993,997,1009,1011,1021,1023,1029,1039,1041,1053,1057,1087,1093,1095,1101,1105,1107,1117,1123,1147,1155,1167,1179,1183,1189,1197,1201,1203,1209,1219,1231,1233,1245,1249,1251,1261,1263,1275,1281,1285,1291,1303,1309,1323,1329,1339,1357,1365,1369,1387,1389,1395,1401,1417,1419,1435,1441,1455,1459,1471,1473,1485,1491,1495,1497,1501,1503,1519,1533,1543,1545,1563,1567,1575,1579,1585,1587,1597,1599,1611,1639,1641,1645,1659,1663,1675,1693,1701,1705,1711,1723,1731,1737,1749,1765,1767,1771,1773,1777,1797,1801,1809,1819,1827,1831,1833,1839,1857,1869,1879,1893,1899,1915,1921,1923,1933,1941,1945,1959,1963,1965,1977,1983,1987,1995,2001,2019,2023,2031,2053,2059,2065,2067,2079,2083,2085,2095,2113,2115,2121,2125,2127,2133,2163,2173,2187,2209,2211,2215,2217,2221,2239,2251,2253,2257,2271,2277,2281,2283,2301,2311,2317,2323,2335,2343,2355,2365,2379,2395,2403,2407,2409,2415,2419,2427,2439,2445,2461,2467,2473,2479,2491,2493,2505,2511,2523,2527,2545,2557,2563,2571,2575,2587,2589,2593,2599,2607,2625,2635,2647,2649,2653,2661,2667,2671,2689,2697,2715,2725,2755,2763,2773,2781,2785,2787,2797,2815,2817,2821,2823,2827,2835,2841,2845,2851,2877,2887,2899,2901,2905,2913,2923,2943,2953,2961,2971,2973,2977,2983,3003,3007,3027,3031,3037,3039,3049,3055,3073,3075,3091,3097,3099,3109,3111,3121,3123,3133,3153,3163,3171,3175,3183,3187,3199,3213,3223,3229,3235,3243,3259,3261,3289,3297,3301,3307,3313,3325,3339,3351,3355,3363,3381,3403,3405,3409,3411,3427,3433,3439,3451,3453,3465,3477,3481,3487,3489,3495,3499,3507,3559,3565,3571,3579,3595,3597,3603,3607,3613,3621,3625,3633,3655,3661,3663,3669,3675,3685,3687,3697,3709,3717,3721,3727,3747,3753,3763,3771,3781,3789,3793,3795,3811,3843,3847,3849,3865,3873,3879,3889,3891,3897,3909,3915,3931,3943,3951,3955,3969,3975,3981,3991,3999,4003,4015,4023,4033,4035,4041,4045,4063,4069,4081,4095,4105,4107,4129,4131,4161,4165,4173,4179,4189,4195,4201,4203,4207,4227,4237,4251,4255,4257,4263,4269,4285,4287,4315,4321,4329,4335,4363,4377,4383,4389,4399,4413,4431,4441,4443,4455,4461,4465,4483,4485,4495,4509,4519,4521,4539,4551,4561,4567,4569,4573,4587,4609,4611,4621,4623,4629,4645,4647,4653,4663,4671,4675,4695,4699,4713,4717,4725,4741,4761,4767,4773,4797,4801,4809,4813,4819,4833,4837,4839,4843,4851,4863,4867,4881,4887,4893,4929,4951,4963,4965,4969,4977,4987,4989,4993,4999,5001,5007,5019,5029,5041,5043,5049,5053,5089,5103,5127,5137,5139,5149,5151,5157,5169,5179,5181,5191,5211,5217,5229,5233,5235,5253,5259,5277,5283,5293,5295,5299,5325,5335,5341,5343,5371,5377,5379,5385,5409,5419,5427,5433,5449,5455,5463,5473,5487,5491,5503,5515,5527,5547,5551,5559,5569,5577,5587,5589,5593,5599,5613,5617,5637,5641,5649,5655,5661,5671,5673,5679,5691,5701,5707,5713,5719,5737,5755,5763,5767,5769,5803,5809,5817,5827,5833,5839,5851,5869,5883,5889,5893,5901,5905,5911,5913,5923,5959,5965,5967,5971,5973,5977,5991,5997,6009,6019,6031,6049,6055,6061,6079,6093,6111,6115,6123,6141,6147,6159,6163,6175,6177,6195,6211,6229,6237,6243,6249,6253,6271,6273,6279,6301,6309,6331,6345,6351,6355,6363,6367,6369,6373,6379,6385,6399,6411,6415,6427,6433,6435,6447,6463,6471,6475,6477,6501,6505,6523,6531,6535,6541,6553,6559,6567,6573,6601,6621,6625,6631,6661,6663,6667,6669,6679,6687,6693,6715,6723,6733,6741,6745,6747,6753,6757,6763,6765,6783,6787,6789,6841,6849,6867,6871,6883,6891,6909,6915,6921,6931,6933,6937,6951,6981,6985,6999,7003,7009,7035,7041,7045,7047,7069,7077,7081,7087,7101,7111,7129,7135,7153,7167,7171,7173,7183,7191,7195,7197,7207,7215,7231,7233,7237,7245,7249,7279,7293,7299,7311,7321,7333,7339,7341,7345,7357,7359,7371,7377,7395,7401,7405,7419,7435,7437,7443,7447,7459,7471,7489,7501,7503,7507,7531,7533,7549,7551,7563,7567,7575,7585,7591,7593,7603,7609,7629,7633,7639,7645,7677,7687,7689,7701,7711,7717,7737,7755,7779,7791,7795,7801,7803,7813,7827,7833,7837,7855,7881,7885,7897,7899,7909,7917,7921,7929,7939,7947,7951,7963,7969,7971,8001,8005,8007,8013,8037,8047,8071,8073,8085,8089,8107,8109,8127,8131,8139,8151,8161,8169,8173,8175,8191,8193,8221,8223,8227,8233,8253,8257,8263,8269,8283,8289,8299,8325,8331,8347,8359,8365,8367,8379,8409,8413,8421,8445,8449,8467,8473,8475,8479,8487,8493,8515,8535,8539,8551,8553,8575,8577,8583,8589,8601,8605,8611,8617,8635,8637,8641,8647,8655,8661,8673,8683,8719,8757,8769,8773,8787,8793,8805,8809,8827,8829,8833,8835,8841,8869,8871,8895,8913,8931,8937,8947,8955,8961,8977,8979,8989,8995,8997,9009,9031,9033,9061,9063,9073,9075,9081,9085,9115,9117,9121,9123,9135,9139,9145,9151,9177,9181,9211,9213,9223,9231,9235,9249,9253,9267,9273,9277,9285,9291,9303,9315,9331,9339,9349,9373,9387,9399,9403,9409,9421,9423,9429,9441,9451,9457,9471,9475,9481,9483,9487,9501,9535,9537,9543,9547,9549,9555,9561,9567,9613,9621,9625,9631,9643,9649,9661,9663,9675,9687,9691,9703,9727,9733,9751,9753,9775,9787,9789,9795,9801,9807,9811,9813,9837,9841,9883,9895,9915,9927,9937,9957,9961,9979,9985,9987,9997,9999,10003,10009,10017,10041,10051,10059,10069,10071,10083,10087,10089,10095,10111,10117,10125,10131,10143,10147,10149,10153,10173,10191,10195,10197,10221,10239,10255,10261,10275,10279,10291,10311,10315,10317,10321,10341,10363,10365,10387,10399,10411,10417,10431,10441,10443,10459,10461,10471,10501,10507,10509,10525,10531,10533,10555,10563,10569,10575,10585,10587,10597,10599,10605,10609,10635,10651,10653,10659,10671,10683,10723,10725,10731,10747,10753,10755,10759,10773,10785,10789,10797,10809,10843,10849,10873,10881,10891,10903,10909,10911,10921,10923,10945,10953,10965,10975,10977,11005,11011,11017,11047,11055,11059,11073,11077,11089,11091,11097,11113,11137,11157,11163,11173,11181,11193,11197,11205,11217,11223,11227,11239,11245,11247,11259,11263,11269,11283,11289,11301,11323,11341,11343,11371,11373,11377,11389,11391,11395,11407,11419,11425,11427,11437,11439,11475,11479,11487,11491,11521,11529,11535,11539,11541,11577,11581,11583,11599,11617,11623,11629,11641,11643,11659,11667,11677,11679,11707,11721,11725,11731,11769,11781,11797,11803,11811,11815,11823,11827,11833,11835,11845,11847,11853,11865,11877,11887,11911,11923,11929,11943,11953,11959,11961,11991,11995,12007,12015,12025,12049,12057,12063,12069,12079,12097,12103,12117,12121,12133,12139,12141,12151,12159,12163,12165,12193,12201,12207,12223,12237,12243,12265,12267,12285,12295,12301,12307,12315,12319,12321,12333,12337,12357,12363,12373,12379,12391,12399,12411,12417,12427,12435,12457,12481,12487,12495,12499,12519,12543,12547,12553,12567,12579,12589,12607,12609,12621,12631,12645,12649,12651,12673,12679,12699,12709,12711,12729,12735,12741,12759,12763,12777,12781,12799,12801,12813,12819,12861,12867,12877,12885,12903,12907,12925,12937,12951,12957,12961,12969,12991,12999,13009,13011,13021,13027,13029,13053,13057,13063,13077,13083,13113,13117,13119,13125,13129,13135,13141,13167,13177,13179,13203,13209,13215,13219,13243,13245,13267,13273,13279,13281,13285,13293,13309,13317,13323,13327,13335,13345,13347,13359,13363,13371,13387,13419,13441,13443,13465,13473,13485,13489,13513,13515,13519,13527,13531,13533,13537,13551,13567,13575,13581,13587,13599,13609,13633,13657,13677,13681,13693,13695,13707,13723,13725,13737,13741,13743,13759,13801,13803,13821,13831,13833,13849,13851,13861,13873,13893,13897,13929,13947,13953,13957,13995,14007,14017,14031,14035,14037,14041,14049,14053,14059,14073,14079,14091,14095,14113,14115,14119,14137,14163,14179,14181,14185,14199,14205,14209,14211,14217,14229,14245,14247,14253,14281,14287,14293,14307,14313,14317,14331,14347,14349,14353,14367,14395,14407,14419,14427,14437,14439,14443,14449,14457,14461,14473,14491,14493,14505,14521,14523,14539,14541,14565,14587,14595,14599,14601,14607,14625,14661,14667,14689,14691,14713,14715,14721,14731,14749,14751,14755,14775,14779,14785,14793,14797,14817,14841,14875,14881,14883,14899,14905,14919,14923,14931,14935,14943,14947,14973,14977,14997
    };
    a[1601] = 15*1000+1;
    n = upper_bound(a,a+1600,n)-a;
    m = upper_bound(a,a+1600,m-1)-a;
    cout<<m-n<<endl;
}

J:链接 输出环

思路比较笨,练了一手lca和kruskal,因为n个点n条边,首先跑一个kruskal,得到n-1条边,然后把这n-1条边建图,
并预处理每个点的深度和该点的祖先(倍增),然后把另外的一条不在最小生成树的边,找出此边的U,V,然后求一个U,V的最近公共祖先fa,然后得到U到fa的路径和V到fa的路径,排序输出。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5, M = N*2, INF = 0x3f3f3f3f;
int f[N];
int h[N],e[M],ne[M],cnt;
int m;
int a,b;
int fa[N][21],depth[N];
struct node{
    int a,b,w;
    bool used ;
    bool operator< (const node &t) const{
        return w < t.w;
    }
}edge[M];
//加边 
void add(int a , int b ){
    e[cnt] = b  , ne[cnt] = h[a] , h[a] = cnt++;
}
//并查集 
int find(int x){
    if (f[x] != x) f[x] = find(f[x]);
    return f[x];
}
//kruskal最下生成树 
void kul(){
    sort(edge,edge+m);
    for(int i=0;i<=m;i++) f[i] = i;  
    for(int i=0;i<m;i++){
        int a = find(edge[i].a), b = find(edge[i].b);
        if(a!=b){
            f[a] = b;
            edge[i].used = true;
        }
    }
}
//建图 
void build(){
    memset(h,-1,sizeof h);
    for(int i=0;i<m;i++){
        if(edge[i].used){
            int a = edge[i].a , b = edge[i].b , w = edge[i].w;
            add(a,b);
            add(b,a);
        }
    }
}
//预处理深度数组和fa 
//fa[i][j] 表示i点第2^j个祖先
//depth[i] 表示i的深度 
void bfs(int root){
    memset(depth , 0x3f , sizeof(depth));
    depth[0] = 0;   
    depth[root] = 1;
    int l=0 , r = -1 , q[N];
    q[++r] = root;
    while(l<=r){
        int now = q[l++];
        for(int i=h[now];~i;i=ne[i]){
            int j = e[i];
            if(depth[j] > depth[now]+1){
                depth[j] = depth[now]+1;
                q[++r] = j;
                fa[j][0] = now; 
                for(int k=1;k<=20;k++){   
                    fa[j][k] = fa[fa[j][k-1]][k-1];
                }
            }
        }
    }
}

//lca求最近公共祖先 
int lca(int x , int y){
    if(depth[x] < depth[y]) swap(x,y);
    for(int k=20;k>=0;k--){
        int fx = fa[x][k];
        if(depth[fx] >= depth[y]) x = fx;
    }
    if(x==y) return x;
    for(int k=20;k>=0;k--){
        int fx = fa[x][k];
        int fy = fa[y][k];
        if(fx != fy) {
            x = fx;
            y = fy;
        }
    }
    return fa[x][0];
}
//记答案 
vector<int> ans;
int main(){
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%d %d",&a,&b);
        edge[i] = {a,b,1};
    }
    kul();
    build();
    bfs(1);
    int x , y ;
    for(int i=0;i<m;i++){
        //找到没有使用发边 
        if(!edge[i].used){
            x = edge[i].a , y = edge[i].b;
            break;
        }
    }

    int fath = lca(x,y);
    ans.push_back(fath);

    while(x!=fath){
        ans.push_back(x);
        x = fa[x][0];
    }
    while(y!=fath){
        ans.push_back(y);
        y = fa[y][0];
    }
    sort(ans.begin() , ans.end());
    for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
    return 0;
}