Organize the template, while measuring the memset,for,fill who is fast ...
Results: Memset fastest, followed by For,fill slowest qaq ....
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn=10000000+Ten; One BOOLPRI[MAXN]; A voidMakepriintN) { - intLIM=SQRT (n); memset (PRI,true,sizeof(PRI)); - for(intI=2; i<=lim;i++)if(Pri[i]) for(intJ=i*i;j<=n;j+=i) pri[j]=false;return; the } -InlineintRead () { - intx=0, sig=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} + while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); - returnx*=Sig; + } AInlinevoidWriteintx) { at if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; - for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } - intN; - voidinit () { inn=read (); Makepri (n); - for(intI=2; i<=n;i++)if(Pri[i]) write (i), ENT; to return; + } - voidWork () { the return; * } $ voidprint () {Panax Notoginseng return; - } the intMain () {init (); work ();p rint ();return 0;}
Coj 2024 Wonderland Saga (v)--a genius awakening Prime sieve